C语言 打印变量在内存中的二进制形式(补码)

void show_bits(int n)
{
	int i = 0;
	for(i=0;i<32;i++)
		printf("%d",(n&(1u<<(31-i)))!=0?1:0);
	putchar('\n');
}

整数的原码 = 整数的补码html

负数的补码:(原码)->(反码)->(反码+1)post

负数的原码:(补码-1)->最高位符号位别动其他均转反码code

转载于:https://www.cnblogs.com/start2014/p/4005764.htmlhtm