Reputation: 97
I have integer variable which has bytes. eg. int var = 128. so, 128 is 128bytes. How can I convert this into hexadecimal format in C language.
Upvotes: 0
Views: 73
Reputation: 75555
A given integer on a given hardware architecture is always represented the same way.
If you are trying to print it out, you can use printf
.
printf("%x\n", var);
Upvotes: 2
Reputation: 47
You can use these:
%x Unsigned hexadecimal integer | 7fa
%X Unsigned hexadecimal integer (uppercase) | 7FA
so you need this:
printf("%x", var); // you can replace %x to %X if you want to be uppercase
Upvotes: 1
Reputation: 9395
Number at memory location is in binary form. You can convert it into any base (or format) you want.
So, int var = 128
is stored in a memory location. You can print it in any format. To print it in hexadecimal, use
printf("%x", var);
It will print var in hexdecimal.
Upvotes: 0