字节溢出时实际发生了什么? [英] What actually happens when a Byte overflows?

查看:164
本文介绍了字节溢出时实际发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当字节溢出时实际发生什么?

What actually happens when a Byte overflows?

说我们有

byte byte1 = 150; // 10010110  
byte byte2 = 199; // 11000111

如果我们现在进行此添加

If we now do this addition

byte byte3 = byte1 + byte2;

我认为我们最终将得到byte3 = 94,但是实际上会发生什么呢?我是否以某种方式覆盖了其他一些内存,或者这完全无害吗?

I think we'll end up with byte3 = 94 but what actually happens? Did I overwrite some other memory somehow or is this totally harmless?

推荐答案

这很简单.它只是进行加法运算,并得到一个8位以上的数字.第九位(为1)刚刚下降",剩下剩下的8位组成数字94.

It's quite simple. It just does the addition and comes off at a number with more than 8 bits. The ninth bit (being one) just 'falls off' and you are left with the remaining 8 bits which form the number 94.

(是的,这是无害的)

这篇关于字节溢出时实际发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆