Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fully print a number in hexadecimal to the terminal?

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++?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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("0x%04X\n", number);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading