|
-
March 21st, 2007, 06:27 PM
#1
[RESOLVED] hex binary etc
Hello, I am puzzled as to how to convert a hex number to a binary and then to a decimal number. According to my book it should be a very simple algorithm, and yet I am puzzled. Can anybody give me a hint ?
I know how to convert between hex/decimal/binary numbers but I don't know how to do that in assembler. I am using NASM.
Any help is appreciated.
-
March 22nd, 2007, 12:12 AM
#2
Re: hex binary etc
I'm assuming you want to convert them to ascii. Binary is fairly simple.
Just load the number into a register shift left, the carry flag will tell you if the next digit is a zero or a one, store it into your buffer, repeat for all the bits in the register.
Converting to decimal requires a bit of knowledge of the ASCII table.
Work on it one byte at a time. Each nibble in the byte represents one hex digit which still needs to be converted into a decimal digit.
-isolate the high order nibble
-OR it with char '0'
-if the result is greater than char '9', then add 7 (not char '7'!) to the result.
-append this into your buffer.
-repeat with low order nibble.
-
March 24th, 2007, 09:07 PM
#3
Re: hex binary etc
Thank you for your help. It works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|