转换原始值



Value: 1,921,222,太大了,不能作为短值存储,所以会发生数字溢出,变成20,678。

谁能演示一下1921222变成20678的过程?如何"绕"到下一个最低值,并从那里开始计数,得到20,678提前谢谢你

在C语言中,Type有2个字节。编译器将每个整数值视为32位或4字节的"整数"。类型(根据编译器的不同而不同)。

short s = 1921222;

在这个句子中你丢失了2个字节的数据:

Information that remains in the variable (2 bytes)
^         ^
00000000 00011101 01010000 11000110   ->  total data (4 bytes, 32 bits)
v        v
Information discarded when you put this value in a short type.

换句话说,你要"裁剪"。数据,只留下符合指定类型的部分。

01010000 11000110

"01010000 11000110"是20678 .

这个网站可以帮助你更好地理解这个过程是如何工作的:https://hexed.it/

最新更新