Home > Back-end >  How to fully print a number in hexadecimal to the terminal?
How to fully print a number in hexadecimal to the terminal?

Time:11-28

I have unsigned 16-bit number that I need to print in hexadecimal to the terminal like this:

0x0FFE

But using printf("0x%X\n", number"); I'm get this:

0xFFE

Is there way to fully print number in hexadecimal on C or C ?

CodePudding user response:

By default, leading zeros are not printed. To print at least 4 characters with leading zeros, use the 0 flag and a field width of 4.

printf("0xX\n", number);
  • Related