当前位置:网站首页>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。
边栏推荐
- Deep Learning Theory - Initialization, Parameter Adjustment
- LeetCode_22_Apr_2nd_Week
- 卷积神经网络入门详解
- sbl_init.asm-适合在编辑模式下看
- Amazon Cloud Technology Build On-Amazon Neptune's Knowledge Graph-Based Recommendation Model Building Experience
- 2020-03-27
- How to grow into a senior engineer?
- file permission management ugo
- Install Minikube Cluster in AWS-EC2
- LeetCode_Nov_5th_Week
猜你喜欢
随机推荐
第二章 STA相关概念
Rules.make-适合在编辑模式下看
浅谈游戏音效测试点
IEEE802.X protocol suite
jdbc:mysql://localhost:3306/student?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8时报错
DRA821 环境搭建
AWS uses EC2 to reduce the training cost of DeepRacer: DeepRacer-for-cloud practical operation
SFTP的用法
Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
双向LSTM
[Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
Windows10重置MySQL用户密码
MNIST手写数字识别 —— 从二分类到十分类
Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
第一章 绪论
强化学习中,Q-Learning与Sarsa的差别有多大?
target has libraries with conflicting names: libcrypto.a and libssl.a.
How to get started with MOOSE platform - an example of how to run the official tutorial
深度学习理论——过拟合、欠拟合、正则化、优化器
Amazon Cloud Technology Build On-Amazon Neptune's Knowledge Graph-Based Recommendation Model Building Experience