当前位置:网站首页>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。
边栏推荐
- MVC自定义配置
- Thunderbolt turns off automatic updates
- An abstract class, internal classes and interfaces
- 【Copy攻城狮日志】飞浆学院强化学习7日打卡营-学习笔记
- 度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
- LeetCode_22_Apr_4th_Week
- [Daily office][shell] Common code snippets
- LeetCode_Dec_3rd_Week
- Brief description of database and common operation guide
- MySQL批量修改时间字段
猜你喜欢
2020-03-27
Code to celebrate the Dragon Boat Festival - Zongzi, your heart
Chapter One Introduction
LeetCode_Dec_3rd_Week
LeetCode_Dec_2nd_Week
Thunderbolt turns off automatic updates
剪映专业版字幕导出随笔
安装pyspider后运行pyspider all后遇到的问题
[Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
CSDN大礼包--高校圆桌派大礼包
随机推荐
Question 1000: Input two integers a and b, calculate the sum of a+b, this question is multiple sets of test data
LeetCode_Nov_3rd_Week
(导航页)OpenStack-M版-双节点手工搭建-附B站视频
[Daily Office][Miscellaneous][vscode]tab space
Tensorflow/Pytorch安装(Anaconda环境下,无版本冲突,亲测有效)
tmux concept and usage
ideal life
Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
Amazon Cloud Technology Build On-Amazon Neptune's Knowledge Graph-Based Recommendation Model Building Experience
Postgresql snapshot
Install Minikube Cluster in AWS-EC2
Code to celebrate the Dragon Boat Festival - Zongzi, your heart
IEEE802.X protocol suite
度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification
CAS无锁队列的实现
彻底删除MySQL教程
[Development miscellaneous][Debug]debug into kernel
file permission management ugo
counting cycle