printing 64 bit hex number
Hi
I have a variable value1=0x5555555555555555; 64 bit I like to printf("the value is %llx\n", value1); the output is a decimal value not in hex. how do I print a hex number from a hex number %x output a decimal to hex but I need to output a hex from hex what modifier I should use? thanks |
If you would do something like this
Quote:
if this doesnt solve the problem whats the type of value1? |
If it's static, then I could use your way of representing it as a string. But it's 64 bit variable that being constantly updated. So, I am not sure the string represenation is viable option.
The variable is declared as unsigned long long |
What you mean is the DISPLAY representation (in hex) of a hex number.
Something like this (pseudo code) mynum = value1 ; mystr = "" ; b = '' ; (char type) While mynum != 0 a = mynum modulo 16 ; If a > 9 b = chr(a+64) else b = char(a+47); EndIf mystr = b + mystr ; mynum = (mynum - a) / 16 ; Endwhile print mystr ; |
long long value1="0x5555555555555555";
printf("the value is %s\n", value1); your just printing here, so it wont matter if its a char or long right? |
Hi w3bd3vil
I try your method, %s but it still output the decimal value. |
That's because he assigned a string to a long long which isn't going to work particularly well. Just using %llx works fine for me. Are you sure it's not printing out on hex? It won't print out the leading 0x (you must specify that yourself), so in your example it should just print out 5555555555555555 which would look decimal unless you "knew" it was a hex number.
Also, be sure you're compiling a 64 bit executable with -m64. |
hi btmiller
I try again now the problem is gcc -c -m64 test.c which would produce the test.o then gcc test.o -o test would complain the x64-64 of test.o (/w -m64) incompatible with i386 output. I try gcc -m64 test.o -o test would give me an error about the ld linker and one of its library. |
Quote:
value1="0x5555555555555555" --> this must be in quotes when I dont input the quotes, this what I get the value is 5555555555555555 using %llx, and segmentation fault with %s |
All times are GMT -5. The time now is 01:27 PM. |