Guidance Forums / wxWidgets (wxWindows) in C++ / Hex Values

Search 搜索
Home Home

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Hex Values
Posted by: IceCreamFlavor 2004-04-11 14:38:07
How do you read the "real" values from hex code?
For example, the hex value: b4 09 cd 21 b8 01 4c cd

If anyone can tell me how to get a single integer\character\whatever from that long string of seemingly random numbers, it would help me tremedously!
   /              \

I'll schoot the ground, make you scared!

I will chop your nuts off!
Message2. Re: Hex Values
Posted by: upCASE 2004-04-12 19:21:39
Well, I don't quite get your question. "How do you read the "real" values from hex code?"
What real values? A hex number is a "real" value...

I guess what you meant was how to transcribe a hex value to a dec value. I'm not going into detail on that one, because I think that you should know this if you want to mess with memory contents.
The hexadecimal number system ranges from 0 to F (meaning 15dec). Normally you deal with "number pairs" like b4, so the maximum value could be FF, or 255dec. In the case of B4 this means -> b=11dec, 11*16+4 = 180dec.
If you want to know what character this resembles -> Grab an ASCII chart and look it up.

To "convert" values you can use sscanf.

#include <stdio.h>

int main(int argc, char* argv[])
    long dec;
    if(argc != 2)
        printf("Usage: %s HEXVALUE\n",argv[0]);
    sscanf(argv[1], "%x", &dec);
    printf("Dec: %ld", dec);
    return 0;

If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
© Thu 2024-6-20  Guidance Laboratory Inc. Hits:0