负数在计算机中存储方式,原码,补码,反码概念
2016-06-21 16:00
519 查看
void test_1_2()
{
long x1 = 2169926;
long x2 = -2169926;
printf("x1 = %ld! x1 = 0x%08x x2 = %ld! x2 = 0x%08x\n", x1, x1, x2, x2);
long temp_l = 0;
long temp_l0 = 0;
long temp_l2 = 0;
long temp_l3 = 0;
long temp_l4 = 0;
long temp_l5 = 0;
temp_l = -x2;
printf("temp_l = %ld! temp_l = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l, temp_l, x2, x2);
temp_l2 = temp_l | 0x80000000;
printf("temp_l2 = temp_l | 0x80000000; temp_l2 = %ld! temp_l2 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l2, temp_l2, x2, x2);
temp_l3 = ~temp_l2;
printf("temp_l3 = ~temp_l2; temp_l3 = %ld! temp_l3 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l3, temp_l3, x2, x2);
temp_l4 = temp_l3 | 0x80000000;
printf("temp_l4 = temp_l3 | 0x80000000; temp_l4 = %ld! temp_l4 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l4, temp_l4, x2, x2);
temp_l5 = temp_l4 + 1;// | 0x80000000;
printf("temp_l5 = temp_l4 + 1; temp_l5 = %ld! temp_l5 = 0x%08x x2 = %ld! x2 = 0x%08x\n*********************\n", temp_l5, temp_l5, x2, x2);
temp_l4 = temp_l5 - 1;
printf("temp_l4 = %ld! temp_l4 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l4, temp_l4, x1, x1);
temp_l3 = temp_l4 & (~0x80000000);
printf("temp_l3 = %ld! temp_l3 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l3, temp_l3, x1, x1);
temp_l2 = ~temp_l3;
printf("temp_l2 = %ld! temp_l2 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l3, temp_l3, x1, x1);
temp_l = temp_l2 & (~0x80000000);
printf("temp_l = %ld! temp_l = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l, temp_l, x1, x1);
}
{
long x1 = 2169926;
long x2 = -2169926;
printf("x1 = %ld! x1 = 0x%08x x2 = %ld! x2 = 0x%08x\n", x1, x1, x2, x2);
long temp_l = 0;
long temp_l0 = 0;
long temp_l2 = 0;
long temp_l3 = 0;
long temp_l4 = 0;
long temp_l5 = 0;
temp_l = -x2;
printf("temp_l = %ld! temp_l = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l, temp_l, x2, x2);
temp_l2 = temp_l | 0x80000000;
printf("temp_l2 = temp_l | 0x80000000; temp_l2 = %ld! temp_l2 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l2, temp_l2, x2, x2);
temp_l3 = ~temp_l2;
printf("temp_l3 = ~temp_l2; temp_l3 = %ld! temp_l3 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l3, temp_l3, x2, x2);
temp_l4 = temp_l3 | 0x80000000;
printf("temp_l4 = temp_l3 | 0x80000000; temp_l4 = %ld! temp_l4 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l4, temp_l4, x2, x2);
temp_l5 = temp_l4 + 1;// | 0x80000000;
printf("temp_l5 = temp_l4 + 1; temp_l5 = %ld! temp_l5 = 0x%08x x2 = %ld! x2 = 0x%08x\n*********************\n", temp_l5, temp_l5, x2, x2);
temp_l4 = temp_l5 - 1;
printf("temp_l4 = %ld! temp_l4 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l4, temp_l4, x1, x1);
temp_l3 = temp_l4 & (~0x80000000);
printf("temp_l3 = %ld! temp_l3 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l3, temp_l3, x1, x1);
temp_l2 = ~temp_l3;
printf("temp_l2 = %ld! temp_l2 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l3, temp_l3, x1, x1);
temp_l = temp_l2 & (~0x80000000);
printf("temp_l = %ld! temp_l = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l, temp_l, x1, x1);
}
相关文章推荐
- openstack 网络
- 启用新博客 http://taney.coding.me , 欢迎访问!
- 位运算-Single Number II(给定一个数组,除了一个数字出现一次,其他都出现三次,求出现一次的数)
- TCP-IP 三次握手-四次挥手
- http://blog.csdn.net/mr_raptor/article/category/799879/3
- 关于ftp和http下载断点续传
- 计算机网络体系结构及简单通信
- HTTP Status Code
- IHS转发,输入根路径,出现欢迎页,如何关闭
- ios htttp网络请求cookie的读取与写入(NSHTTPCookieStorage)
- 基于http协议的svn服务器
- 网络中文乱码问题 utf-8
- 笔记+R︱信用风险建模中神经网络激活函数与感知器简述
- 数据结构与算法集锦
- 数据结构实验之栈:行编辑器
- 使用httpclient必须知道的参数设置及代码写法、存在的风险
- Android实现网络多线程文件下载
- HTTP协议
- NFS - Network File System网络文件系统
- HTTP状态