使用32位cpu的64位总和

编程入门 行业动态 更新时间:2024-10-13 00:32:24
本文介绍了使用32位cpu的64位总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在下面的问题中需要帮助。 我有一个知道在32位上进行计算的cpu(unsigned 整数( 写一个函数,得到2个64位数字并返回它们的总和。 我从以下结构开始。 typedef struct { unsigned int low; unsigned int high; } 64bits; 并定义nums 64bits num1.num2; 1.我知道无符号整数的极限是~64000 的情况从0开始溢出它。? 2.有人可以为这个问题添加解决方案吗?

Hi, I need help in the following question . I have a cpu that knows to do the computations on 32 bits(unsigned integer( write a function that gets 2 64 bits numbers and return their sum. I start with the following structure. typedef struct{ unsigned int low; unsigned int high; }64bits; and define the nums 64bits num1.num2; 1.I know that the limit of unsigned integer is ~64000 what happend in case of overflow it start again from 0.? 2.could someone add solution for the question?

推荐答案

5月13日18:17,sarahh< cohen ... @ gmailwrote: On 13 May, 18:17, sarahh <cohen...@gmailwrote: 您好,我在以下问题中需要帮助。 我有一个知道在32位上进行计算的cpu(无符号 整数( 写一个得到2 6的函数) 4位数字并返回它们的总和。 我从以下结构开始。 typedef struct { unsigned int low; unsigned int high; } 64位; 并定义nums 64bits num1.num2; Hi, I need help in the following question . I have a cpu that knows to do the computations on 32 bits(unsigned integer( write a function that gets 2 64 bits numbers and return their sum. I start with the following structure. typedef struct{ unsigned int low; unsigned int high; }64bits; and define the nums 64bits num1.num2;

您是否正在使用C89编译器 表示您没有未签名的长期 可用吗?

Are you working on a C89 compiler which means you don''t have unsigned long long available ?

1.我知道无符号整数的限制是〜64000发生的事情 溢出的情况它从0开始。? 1.I know that the limit of unsigned integer is ~64000 what happend in case of overflow it start again from 0.?

UINT_MAX保证至少为65535.它可以更多,实际上标准没有指定 上限。是的,它会在到达时徘徊 UINT_MAX + 1

UINT_MAX is guaranteed to be at least 65535. It could be a lot more , in fact the standard doesn''t specify an upper bound. And yes it will wrap around upon reaching UINT_MAX + 1

2.有人可以为问题添加解决方案吗? 2.could someone add solution for the question?

这是家庭作业吗?

Is it homework ?

sarahh写道: sarahh writes: 1.我知道无符号整数的极限是~64000 1.I know that the limit of unsigned integer is ~64000

....在主机上,unsigned int是32位的就像你的问题,是的....

....on a host where unsigned int is 32-bit like on your question, yes....

如果发生溢出,它会从0开始再次发生什么? what happend in case of overflow it start again from 0.?

是的。使用32位无符号int,0xffffffffU(所有位= 1)+ 1U == 0. 无符号算术定义为模数(最大值+ 1)算术。 (严格来说,这不是所谓的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 to signed integers, where the result is not defined.)

2.是否有人为问题添加解决方案? 2.could someone add solution for the question?

家庭作业的重点是边做边学。但是如果你需要一个提示: 想想你如何手工添加两位数字,并认为 的低位和高位是一个数字的两位数。 (在基础0x100000000 而不是基数10,但是嘿......)你需要以某种方式检查 是否有来自添加低的进位数字。 - Hallvard

The 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 think of low and high as the two digits of a number. (In base 0x100000000 instead of base 10, but what the hey...) You need to check somehow whether there was carry from adding the "low" digits. -- Hallvard

在13×?×?×?,20 :45,Hallvard B Furuseth< hbfurus ... @ usit.uio.no> 写道: On 13 ×?×?×?, 20:45, Hallvard B Furuseth <h.b.furus...@usit.uio.no> wrote: sarahh写道: sarahh writes: 1.我知道主机上无符号整数的限制为~64000 1.I know that the limit of unsigned integer is ~64000

...其中unsigned int在你的问题上是32位的,是的....

...on a host where unsigned int is 32-bit like on your question, yes....

如果发生溢出,它会从0开始再次发生什么? what happend in case of overflow it start again from 0.?

是的。使用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 to signed integers, where the result is not defined.)

2.是否可以为此问题添加解决方案? 2.could someone add solution for the question?

家庭作业的重点是边做边学。但是如果你需要一个提示: 想想你如何手工添加两位数字,并认为 的低位和高位是一个数字的两位数。 (在基础0x100000000 而不是基数10,但是嘿......)你需要以某种方式检查 是否有来自添加低的进位数字。 - Hallvard

The 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 think of low and high as the two digits of a number. (In base 0x100000000 instead of base 10, but what the hey...) You need to check somehow whether there was carry from adding the "low" digits. -- Hallvard

谢谢,知道我更了解它怎么样没有签名,如果我加上max + 1,会发生什么?b / b?

Thanks,know I understand it better what about not unsigned, what happend if I add to max+1 ?

更多推荐

使用32位cpu的64位总和

本文发布于:2023-11-05 18:29:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:总和   cpu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!