cformatintegerprintfhex

How can I display hexadecimal numbers in C?


I have a list of numbers as below:

0, 16, 32, 48 ...

I need to output those numbers in hexadecimal as:

0000,0010,0020,0030,0040 ...

I have tried solution such as:

printf("%.4x", a); // Where a is an integer

But the result that I got was:

0000, 0001, 0002, 0003, 0004 ...

I think I'm close there. How can I fix it?

I'm not so good at printf in C.


Solution

  • Try:

    printf("%04x",a);
    

    More here