K
Keep Asking
I totally mess up my last post. Let me start it again.
I want print hex value from char, on 64 platform.
uname -a
Linux myang-desktop 2.6.24-26-generic #1 SMP Tue Dec 1 17:55:03 UTC
2009 x86_64 GNU/Linux
gcc --version
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
Hese is the program
#include <stdio.h>
#include <stdio.h>
int main()
{
char array[] = {0x7f,0x55,0x86,0x91};
int i=0;
for(i=0; i<4; i++)
{
printf("%02x\n", (unsigned char)array);
printf("%02x\n", (unsigned int)array);
printf("%02x\n", array);
}
}
Here is the output
../a.out
7f
7f
7f
55
55
55
86
ffffff86
ffffff86
91
ffffff91
ffffff91
Only line
printf("%02x\n", (unsigned char)array);
gives me what I want. Can anyone explain?
Thanks,
I want print hex value from char, on 64 platform.
uname -a
Linux myang-desktop 2.6.24-26-generic #1 SMP Tue Dec 1 17:55:03 UTC
2009 x86_64 GNU/Linux
gcc --version
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
Hese is the program
#include <stdio.h>
#include <stdio.h>
int main()
{
char array[] = {0x7f,0x55,0x86,0x91};
int i=0;
for(i=0; i<4; i++)
{
printf("%02x\n", (unsigned char)array);
printf("%02x\n", (unsigned int)array);
printf("%02x\n", array);
}
}
Here is the output
../a.out
7f
7f
7f
55
55
55
86
ffffff86
ffffff86
91
ffffff91
ffffff91
Only line
printf("%02x\n", (unsigned char)array);
gives me what I want. Can anyone explain?
Thanks,