(严格来说,这不是所谓的C语言溢出 - 正是因为它定义明确。溢出是发生在 $ b上的事情$ b签名整数,其结果未定义。)Yes. With 32-bit unsigned int, 0xffffffffU (all bits = 1) + 1U == 0.Unsigned arithmetic is defined as modulo-(max value + 1) arithmetic.(Strictly speaking this is not what is called overflow in the C language- precisely because it is well-defined. "overflow" is what happens tosigned integers, where the result is not defined.) 家庭作业的重点是边做边学。但是如果你需要一个提示: 想想你如何手工添加两位数字,并认为 的低位和高位是一个数字的两位数。 (在基础0x100000000 而不是基数10,但是嘿......)你需要以某种方式检查 是否有来自添加低的进位数字。 - HallvardThe point of homework is to learn by doing. But if you need a hint:Think of how you do addition of two-digit numbers by hand, and thinkof low and high as the two digits of a number. (In base 0x100000000instead of base 10, but what the hey...) You need to check somehowwhether there was carry from adding the "low" digits.--Hallvard ...其中unsigned int在你的问题上是32位的,是的.......on a host where unsigned int is 32-bit like on your question, yes.... 是的。使用32位无符号int,0xffffffffU(所有位= 1)+ 1U == 0 .. 无符号算术定义为模数(最大值+ 1)算术。 (严格来说,这不是所谓的C语言溢出 - 正是因为它定义明确。溢出是发生在 签名的整数,其结果未定义。)Yes. With 32-bit unsigned int, 0xffffffffU (all bits = 1) + 1U == 0..Unsigned arithmetic is defined as modulo-(max value + 1) arithmetic.(Strictly speaking this is not what is called overflow in the C language- precisely because it is well-defined. "overflow" is what happens tosigned integers, where the result is not defined.) 家庭作业的重点是边做边学。但是如果你需要一个提示: 想想你如何手工添加两位数字,并认为 的低位和高位是一个数字的两位数。 (在基础0x100000000 而不是基数10,但是嘿......)你需要以某种方式检查 是否有来自添加低的进位数字。 - HallvardThe point of homework is to learn by doing. But if you need a hint:Think of how you do addition of two-digit numbers by hand, and thinkof low and high as the two digits of a number. (In base 0x100000000instead of base 10, but what the hey...) You need to check somehowwhether there was carry from adding the "low" digits.--Hallvard 谢谢,知道我更了解它怎么样没有签名,如果我加上max + 1,会发生什么?b / b?Thanks,know I understand it better what about not unsigned, whathappend if I add to max+1 ? 这篇关于使用32位cpu的64位总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 14:52