Path: rQdQ!remarQ73!supernews.com!remarQ.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail
From: jizhang123@my-deja.com
Newsgroups: alt.chinese.computing,asu.comp.academic,comp.os.msdos.programmer,comp.programming
Subject: Re: HEX to Decimal's ASCII ? pls. help
Date: Fri, 25 Jun 1999 16:03:57 GMT
Organization: Deja.com - Share what you know. Learn what you don't.
Lines: 65
Message-ID: <7l0994$7vg$1@nnrp1.deja.com>
References: <7kvuhk$h9u8@pegasus.hkstar.com> <7kvvsm$51c$1@taliesin.netcom.net.uk>
NNTP-Posting-Host: 132.246.96.98
X-Article-Creation-Date: Fri Jun 25 16:03:57 1999 GMT
X-Http-User-Agent: Mozilla/2.0S (X11; I; IRIX 6.2 IP20)
X-Http-Proxy: 1.0 x36.deja.com:80 (Squid/1.1.22) for client 132.246.96.98
Xref: rQdQ alt.chinese.computing:21754 comp.os.msdos.programmer:108422 comp.programming:88842
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)

I guess Michael Stewart does not use
C, otherwise, "7BH" would be written
as 0x7b.

You can convert hex to decimal yourself. No matter how big the hex value
is (or how many number of digits you have in a hex), the rule
is:

  decimal_value = (16^0) * digit_0th
  +  (16^1) * digit_1st
  +  (16^2) * digit_2nd
  +  (16^3) * digit_3rd
  +  (16^4) * digit_4th
  +  ....

so 0x7b = (16^0) * b
        + (16^1) * 7
        = 11 + 112
        = 123

then you assume decimal value as
a string, and one by one translate

     0 -> 30
     1 -> 31
     2 -> 32
     ...
     9 -> 39

ASCII coding 0x30 is letter 0
0x31 is letter 1, 0x32 is letter 2
...

Ji Zhang <jizhang@www.fhy.net>
   http://www2.fhy.net

In article <7kvvsm$51c$1@taliesin.netcom.net.uk>,
  "Michael Stewart" <mike@reggin.freeserve.co.uk> wrote:
> felix wrote in message <7kvuhk$h9u8@pegasus.hkstar.com>...
> >Could anyone tell me how to translate a HEX to Decimal's ASCII code
> >e.g. 7BH -> 123(decimal) -> 31 32 33 (ASCII)
>
> It often helps if you specify what language you are working in.
>
> I'm not sure how you get 31 32 33 from 123 thought, assuming you work in C
> and you want the ASCII characters '1', '2' and '3' then this may help.
>
> char str_chars[33];
> char *chptr;
>
> int num = <number to process>
>
> (void)itoa(num, str_chars, 2);
>
> chptr = str_chars;
>
> while (chptr) {
>    printf ("%d\n", *chptr++);
> }
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.