Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Hex Values

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Hex Values
#3804
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!
______________________
   /              \
    IceCreamFlavor
   \______________/
______________________

I'll schoot the ground, make you scared!

I will chop your nuts off!
Message2. Re: Hex Values
#3808
Posted by: upCASE 2004-04-12 19:21:39
Hi!
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]);
        exit(1);
    }
    sscanf(argv[1], "%x", &dec);
    printf("Dec: %ld", dec);
    
    return 0;
}

upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2021-7-28  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0