[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.
[365 byte] By [
slewrate] at [2007-11-20 6:25:17]

# 1 Re: [RESOLVED] 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.