HEX to Decimal ASCII code. pls help

Quote:

> So now you have the Binary value of 120d. Use this next table to

> find the Hex value of 01111000. You should remember this table.

> 0001 =1

> 0010 =2

> 0011 =3

> 0100 =4

> 0101 =5

> 0110 =6

> 0111 =7

> 1000 =8

> 1001 =9

> 1010 =A

> 1011 =B

> 1100 =C

> 1101 =D

> 1110 = E

> 1111 =F

> So now you can find the Hex value of the binary value of 120d which is

> 78.

> I think there is another way, but this one works more effectively.....it

> just takes longer.

Here is another method of changing from Binary to ASCII Hex :

"There is a well-known algorithm for converting a binary number between one

and fif{*filter*} to its equivalent hex form in ASCII that requires only four

assembly language instructions. Assuming that the number to convert is in AL,

the following sequence performs the conversion:

add al,90h

daa

adc al,40h

daa

This instruction sequence is, as far as we know, the shortest (16 cycles)

self-contained routine to convert a binary number to hex." (Ken Sykes, David

Ogle)

This was taken from an article by mammon_ in the Assembly Programming Journal,

Issue 3.

See http://www.*-*-*.com/

Personally, I just use a lookup table like Jeff suggested, but I thought that

this solution was quite elegant. If you are only doing the conversion once in

your program, this method would be smaller (since you don't need the 16 byte

hex table). Otherwise, the lookup table is smaller and faster.

- Michael

PS You would also need the value for zero in your hex table, Jeff :-)