C语言八进制和十六进制数

一 赋值

int dex = 100;// 默认十进制
int oct = 0144;// 八进制,以0开始
int hex = 0x64;// 十六进制,以0x开始

二 输出

void show(int x)
{
    printf("dec = %d; octal = %o; hex = %x\n",x,x,x);
    printf("dec = %d; octal = %#o; hex = %#x\n",x,x,x);
}

例如:

int num = 100;
show(num);

输出结果:

dec = 100; octal = 144; hex = 64

dec = 100; octal = 0144; hex = 0x64



你可能感兴趣的:(C/C++)