移位
//测试移位 #include <stdio.h> int main() { //测试存储数据的方式:补码 int a = -1; unsigned int b = 1U; printf("有符号数a的值是%x\n", a); printf("无符号数b的值是%x\n", b); //测试原码左移 a = a << 3; b = b << 3; printf("有符号数a左移三位的值是%x\n", a); printf("有符号数a左移三位的值是%d\n", a); printf("无符号数b左移三位的值是%x\n", b); //测试负数补码左移 a = a | 1; printf("有符号数a的值是%x\n", a); a = a << 29; printf("有符号数a左移29位的值是%x\n", a); //测试右移 a = a << 2; b = 1; a = a >> 3; b = b >> 3; printf("有符号数a右移三位的值是%x\n", a); printf("有符号数a右移三位的值是%d\n", a); printf("无符号数b右移三位的值是%x\n", b); return 0; }