Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Convert hex to string

by Ras (Acolyte)
on Dec 29, 2001 at 05:01 UTC ( [id://135034]=note: print w/replies, xml ) Need Help??


in reply to Re: Convert hex to string
in thread Convert hex to string

Well i'm trying to convert that hex number "9210" into a string. And believe me this is not homework. Some one in my office wants to know if this can be done.

Replies are listed 'Best First'.
Re: Re: Re: Convert hex to string
by talexb (Chancellor) on Dec 29, 2001 at 07:30 UTC
    Someone in your office wants to know if it can be done?

    That's got to be the most hilarious thing I've heard in a long time. And do they have two tufts of pointy hair as well?

    Seriously, though .. you need to understand number bases to understand what's going on here. Just telling you that the answer is 63,360 (which it isn't) isn't going to help you.

    You need to decompose the number into tens, hundreds and thousands, then remember that in hexadecimal, ten is actually 16, a hundred is actually 256 and a thousand is actually 4,096. So then it's 9 x 4,096 plus .. you get the idea.

    Alternatively, you could convert 0x9210 to binary, giving 1001 0010 0001 0000, then just multiplying by the appropriate powers of two. Actually, that looks pretty easy .. 16,384 + 4096 .. well, you get the idea.

    Alternatively, in C you could sscanf the number in using "%x", then print it out using "%d" and get the machine do to the conversion.

    The Windows calculator application also converts between hex and decimal.

    So, anyway, good luck.

    --t. alex

    "Excellent. Release the hounds." -- Monty Burns.

Re: Re: Re: Convert hex to string
by Fastolfe (Vicar) on Dec 29, 2001 at 09:53 UTC
    After reading all of these posts, I still have no idea what your requirements are. What should this string be? Do you have an example of the input and output?

    You may just be looking to use the %x format for sprintf, which takes a number and constructs a hexadecimal representation of it. But since you say 9210 is a hex number to begin with, I haven't a clue what this string should contain. A decimal representation of the number? Use hex. Otherwise be more specific.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://135034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found