How to display hexadecimal numbers in C?

前端 未结 4 1048
感动是毒
感动是毒 2020-12-07 15:27

I have a list of numbers as below:

0, 16, 32, 48 ...

I need to output those numbers in hexadecimal as:

00

4条回答
  •  难免孤独
    2020-12-07 16:26

    You can use the following snippet code:

    #include
    int main(int argc, char *argv[]){
        unsigned int i;
        printf("decimal  hexadecimal\n");
        for (i = 0; i <= 256; i+=16)
            printf("%04d     0x%04X\n", i, i);
        return 0;
    }
    

    It prints both decimal and hexadecimal numbers in 4 places with zero padding.

提交回复
热议问题