如何从2个32位值计算64位结果 [英] how to compute 64 bit result from 2 32 bit values

查看:78
本文介绍了如何从2个32位值计算64位结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试从2个32位

寄存器计算64位结果,如何将进位输入更高的字?

也是%lld正确吗?

#include< stdio.h>


long long int64(long x,int y);

main()

{

printf("%lld \ n",int64(0xffffffff,1));


}


long long int64(long x,int y)

{

返回x + y;

}


Ans应为0x100000000。

谢谢

雪橇。

解决方案

csledge写道:




我试图从2个32位

寄存器计算64位结果,如何将进位输入更高的字?

还是%lld是否正确?



你不会从标准C那里得到答案。在C中写下你的测试

,用你最喜欢的选项编译生成asm,看看它是如何在你的平台上完成的。


csledge写道:




我试图从2个32位

寄存器计算64位结果,如何将进位输入更高的字?

也是%lld正确吗?

#include< stdio.h>


long long int64(long x,int y);

main()

{

printf("%lld \ n",int64(0xffffffff,1));


}


long long int64(long x,int y)

{

返回x + y;

}


Ans应为0x100000000。



%lld是打印长long值的正确格式说明符。

强制添加两个更窄的类型很长的

算术,添加一个演员:


long long int64(long x,int y)

{

返回(很长)x + y;

}


csledge写道:
< blockquote class =post_quotes>


我试图从2个32位

寄存器计算64位结果,如何获取进位进入更高的单词?

也是%lld正确吗?

#include< stdio.h>


long long int64( long x,int y);

main()

{

printf("%lld \ n",int64(0xffffffff, 1));


}


long long int64(long x,int y)

{

返回x + y;

}


Ans应为0x100000000。

谢谢

雪橇。



怎么样

返回(long long)x + y;


以防你运行目标(很长)比(长)大吗?


和所需的#include?


我对你的函数名有点困惑并且没有std标题,

这似乎让人联想到一些常见的扩展名。


Hi,
I am trying to compute a 64 bit result from 2 32 bit
registers, How do I get the carry into the higher word ?
Also is %lld correct ?
#include<stdio.h>

long long int64( long x, int y);
main()
{
printf("%lld \n",int64(0xffffffff,1));

}

long long int64( long x, int y)
{
return x + y;
}

Ans should be 0x100000000.
Thanks
Sledge.

解决方案

csledge wrote:

Hi,
I am trying to compute a 64 bit result from 2 32 bit
registers, How do I get the carry into the higher word ?
Also is %lld correct ?

You won''t get an answer this way from Standard C. Write your test
in C, compile with your favorite option to generate asm, and see how
it''s done on your platform.


csledge wrote:

Hi,
I am trying to compute a 64 bit result from 2 32 bit
registers, How do I get the carry into the higher word ?
Also is %lld correct ?
#include<stdio.h>

long long int64( long x, int y);
main()
{
printf("%lld \n",int64(0xffffffff,1));

}

long long int64( long x, int y)
{
return x + y;
}

Ans should be 0x100000000.

%lld is the correct format specifier for printing a long long value.
To force an addition of two narrower types to be done in long long
arithmetic, add a cast:

long long int64( long x, int y)
{
return (long long) x + y;
}


csledge wrote:

Hi,
I am trying to compute a 64 bit result from 2 32 bit
registers, How do I get the carry into the higher word ?
Also is %lld correct ?
#include<stdio.h>

long long int64( long x, int y);
main()
{
printf("%lld \n",int64(0xffffffff,1));

}

long long int64( long x, int y)
{
return x + y;
}

Ans should be 0x100000000.
Thanks
Sledge.

How about
return (long long)x + y;

in case you are running a target where (long long) is bigger than (long) ?

and the required #include ?

I was a little confused by your function name and lack of std headers,
which seems reminiscent of some common extensions.


这篇关于如何从2个32位值计算64位结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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