当前位置:网站首页>C语言无符号整型运算
C语言无符号整型运算
2022-08-04 05:31:00 【crazy__xieyi】
下面根据一道题来详细说说无符号整型运算,在这之前大家要先了解一下数据是如何在内存中存储的,参考我之前写的这篇博客:深度剖析数据在内存中的存储_crazy__xieyi的博客-CSDN博客
例题:
下面程序执行结果为
int main() { unsigned char a = 200; unsigned char b = 100; unsigned char c = 0; c = a + b; printf(“%d %d”, a+b,c); return 0; }
首先我们应该知道char的范围是-128-127; unsigned char 的范围是0-255;
unsigned char a = 200;
00000000 00000000 00000000 11001000
11001000 -a 截断
unsigned char b = 100;
00000000 00000000 00000000 01100100
01100100 - b 截断
下面我们要注意的是在进行c=a+b的运算时,是要进行整型提升的,所以
a 00000000 00000000 00000000 11001000
b 00000000 00000000 00000000 01100100
a+b 00000000 00000000 00000001 00101100
00101100-c 截断
又因为C的类型还是unsigned的,发生截断,所以结果为300 44。
边栏推荐
- LeetCode_22_Apr_4th_Week
- Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
- FAREWARE ADDRESS
- 剪映专业版字幕导出随笔
- [Daily office][shell] Common code snippets
- 2020-03-27
- LeetCode_Dec_3rd_Week
- MVC自定义配置
- 第一章 绪论
- target has libraries with conflicting names: libcrypto.a and libssl.a.
猜你喜欢
随机推荐
IEEE802.X协议族
MNIST手写数字识别 —— 图像分析法实现二分类
LeetCode_22_Apr_4th_Week
Cut the hit pro subtitles export of essays
[日常办公][shell]常用代码段
tmux concept and usage
双向LSTM
LeetCode_Dec_1st_Week
Copy Siege Lion 5-minute online experience MindIR format model generation
剪映专业版字幕导出随笔
管道重定向
第二章 STA相关概念
Implementation of CAS lock-free queue
题目1000:输入两个整数a和b,计算a+b的和,此题是多组测试数据
[日常办公][ssh]cheatsheet
文件编辑器
Copy攻城狮的年度之“战”|回顾2020
典型CCN网络——efficientNet(2019-Google-已开源)
LeetCode_Nov_4th_Week
fuser 使用—— YOLOV5内存溢出——kill nvidai-smi 无pid 的 GPU 进程









