[A83] Re: hex <-> bin <-> dec techniques


[Prev][Next][Index][Thread]

[A83] Re: hex <-> bin <-> dec techniques




> Can somebody give me the techniques to change numbers
> between hex, bin and dec. Maybe also a method to show
> that hex, bin or dec...

What do you mean? I suppose you have the numbers as ASCII 
strings. When converting from/to decimal, you have to first 
get the numbers in binary form, sinc you need to do many 
calculations on them: divisions by 10 in series, and taking 
the remainders for each digit.

Hex<->Bin is quite trivial, as four binary digits are 
equivalent to one hexadecimal digit. You need to do no more 
than associating the 16 combinations with each other.

BTW here's a little trick to convert a 4-bit number in A 
into an ASCII character (it won't work with A values 
greater than 15, of course):

add a,$90
daa
adc a,$40
daa

[numbers greater than 9 will be capital letters]

PG




References: