HEX to Decimal ASCII code. pls help 
Author Message
 HEX to Decimal ASCII code. pls help

Could anyone tell me how to translate a HEX to Decimal's ASCII code
e.g. 7BH -> 123(decimal) -> 31 32 33 (ASCII)

please help.

thanks.



Wed, 12 Dec 2001 03:00:00 GMT  
 HEX to Decimal ASCII code. pls help
Heres an example with some comments below it.

Changing Decimal 120 to Binary (First step to changing to Hex)

120d
                                 0     1     3     7     15     30     60
120
                                         1     1    1       1       0
0         0
;top line started with 120 at the far right of the page.  Divide by two and
put the remainder under the being divided into(120/2=60 remainder=0).  Take
the new number (quotient) and divide by two again.  Put the
remainder(60/2=30 remainder=0) under the dividend (60).  Continue to do this
untill the quotient (answer) is 0.  Add zeroes to the beginning of the
binary answer to make it 8 bits or 16 bits (if answer is longer than 8 bits)
..
        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.

I'm not ssure if this answers your question.  The best way to find any value
(Hex->ASCII, Dec->ASCII) is get a Standard ASCII Codes/Characters table.   I
have one right here,  email me if you want a scan of it.



Wed, 12 Dec 2001 03:00:00 GMT  
 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 :-)



Thu, 13 Dec 2001 03:00:00 GMT  
 HEX to Decimal ASCII code. pls help
Hi,


Quote:
> 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

what about

cmp  al,10    ; 0..9: set carry;        A-F: clear carry
sbb  al,69h   ; 0..9->96h..9Fh; set AC  A-F-> A1h..A6h; clear AC; set CF
das           ; 0..9->30h..3Fh;         A-F-> 41h..46h

? I don't know who found this one (I've only seen a few people using it
and I'm using it, too), but it's shorter (at least in size) than the
above one.

Bertram



Thu, 13 Dec 2001 03:00:00 GMT  
 HEX to Decimal ASCII code. pls help
Hi,
    Try this :-

    cmp    al,10
    sbb    al, 69h
    das

    It will convert(AL) nibble (0 to 0F hex) into an ASCII char.

regards
    TAD

Quote:

>Could anyone tell me how to translate a HEX to Decimal's ASCII code
>e.g. 7BH -> 123(decimal) -> 31 32 33 (ASCII)

>please help.

>thanks.



Thu, 13 Dec 2001 03:00:00 GMT  
 HEX to Decimal ASCII code. pls help

Quote:

> Hi,

> what about

> cmp  al,10    ; 0..9: set carry;        A-F: clear carry
> sbb  al,69h   ; 0..9->96h..9Fh; set AC  A-F-> A1h..A6h; clear AC; set CF
> das           ; 0..9->30h..3Fh;         A-F-> 41h..46h

> ? I don't know who found this one (I've only seen a few people using it
> and I'm using it, too), but it's shorter (at least in size) than the
> above one.

> Bertram

Thanks for the tip!! After a bit of thought on the matter, I realised that a version
without a lookup table would be a lot better for my needs. Not only would I save the
16 bytes for the lookup table, but it would also mean I wouldn't have to load DS in
my number display functions, which means I wouldn't have to save and restore DS,
etc. etc. This all means that your version is probably smaller and faster than a
lookup table.

- Michael



Sun, 16 Dec 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. HEX to Decimal ASCII code. pls help

2. Hex to Decimal ASCII Conversion Code?

3. Hex to Decimal ASCII Conversion Code?

4. Ascii to Hex, Hex to Ascii convertion

5. Hex to Decimal ASCII ?

6. want routine to convert hex to decimal thence to ascii - anyone h elp

7. printf: hex to decimal to hex?

8. Convert from binary to decimal, hex to decimal etc

9. Hex to decimal code (32 bit)

10. **CORRECTION** to Binary to Decimal ASCII Code

11. 16-bit signed binary to binary coded decimal(BCD) ascii

12. from ASCII to HEX code

 

 
Powered by phpBB® Forum Software