user2737926
user2737926

Reputation: 97

Byte stored in integer format to Hexadecimal Conversion

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

Answers (3)

merlin2011
merlin2011

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

Itra
Itra

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

doptimusprime
doptimusprime

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

Related Questions