int64来自int 32 [英] int64 from int 32

查看:83
本文介绍了int64来自int 32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



出于某种原因,下面的代码并没有像我期望的那样产生结果。


#include< stdio.h>


int main()

{


int hi = 0xff;

int low = 0xee;

很长很大;

big =((long long)hi)<< 32 |低;


printf("%16x \ n",大);


}


我迷失了,试图找出我正在制造的错误。你可以帮助我

out。它是编译器依赖的吗?


Deepak

Hi,
For some reason the below code doesnt produce results as i expect.

#include<stdio.h>

int main()
{

int hi=0xff;
int low=0xee;
long long big ;
big = ((long long) hi ) << 32 | low;

printf("%16x \n ",big);

}

I am lost trying to figure out the mistake i am making.Can you help me
out.Is it compiler dependent?

Deepak

推荐答案

Peerless< pe ************* @ gmail.comwrites:
Peerless <pe*************@gmail.comwrites:



出于某种原因,下面的代码并没有像我预期的那样产生结果。


#include< stdio.h>


int main()

{


int hi = 0xff;

int low = 0xee;

long long big;

big =((long long)hi)<< 32 |低;


printf("%16x \ n",大);


}


我迷失了,试图弄清楚我正在制造的错误。你可以帮助我

out.Is编译依赖?
Hi,
For some reason the below code doesnt produce results as i expect.

#include<stdio.h>

int main()
{

int hi=0xff;
int low=0xee;
long long big ;
big = ((long long) hi ) << 32 | low;

printf("%16x \n ",big);

}

I am lost trying to figure out the mistake i am making.Can you help me
out.Is it compiler dependent?



printf的%x说明符需要一个unsigned参数,而不是很长的
长。使用%llx将使用unsigned long long。所以你可能想要


unsigned long long big;

big =((unsigned long long)hi)<< 32 |低;

printf("%16llx \ n",大);


顺便说一下,这符合C99标准,所以它应该是'b $ b编译器依赖


The %x specifier for printf expects an unsigned argument, not a long
long. Using %llx will use an unsigned long long. So you might want

unsigned long long big;
big = ((unsigned long long)hi) << 32 | low;
printf("%16llx\n", big);

This conforms to the C99 standard, by the way, so it shouldn''t be
compiler dependent.





Peerless写道:


Peerless wrote:



出于某种原因,下面的代码并没有像我期望的那样产生结果。


#include< stdio.h>


int main()

{


int hi = 0xff;

int low = 0xee;

long long big;

big =((long long)hi)<< 32 |低;


printf("%16x \ n",大);


}


我迷失了,试图弄清楚我正在制造的错误。你可以帮助我

out.Is编译依赖?
Hi,
For some reason the below code doesnt produce results as i expect.

#include<stdio.h>

int main()
{

int hi=0xff;
int low=0xee;
long long big ;
big = ((long long) hi ) << 32 | low;

printf("%16x \n ",big);

}

I am lost trying to figure out the mistake i am making.Can you help me
out.Is it compiler dependent?



支持''long long''取决于编译器,因为并非所有

编译器在这方面都符合C99标准。但是,如果

一直是您的问题,那么您的代码将永远不会编译。


我强烈建议您在执行时使用无符号类型

移位或位掩码操作。但是,对于你的程序中涉及的特定值

,这不是问题。


有什么问题是''​​大''是一个long long,你使用

%16x作为你的格式代码,这需要一个unsigned int。参数。

将所有内容更改为无符号类型后,您应该使用

"%16llx",它需要unsigned long long。参数。

Support for ''long long'' is compiler dependent, because not all
compilers conform to the C99 standard in that regard yet. However, if
that had been your problem, your code would never have compiled.

I strongly recommend using unsigned types whenever you are performing
shifts or bit-masking operations. However, for the particular values
involved in your program, that''s not a problem.

What is a problem is that ''big'' is a "long long", and you''re using
%16x as your format code, which requires an "unsigned int" argument.
After changing everything to an unsigned type, you should use
"%16llx", which expects an "unsigned long long" argument.


Peerless< pe ************* @ gmail.comwrites:
Peerless <pe*************@gmail.comwrites:

由于某种原因,下面的代码并没有像我期望的那样产生结果。


#include< stdio.h>


int main()

{


int hi = 0xff;

int low = 0xee;

long long big;

big =((long long)hi)<< 32 |低;


printf("%16x \ n",大);


}


我迷失了,试图弄清楚我正在制造的错误。你可以帮助我

out.Is编译依赖?
For some reason the below code doesnt produce results as i expect.

#include<stdio.h>

int main()
{

int hi=0xff;
int low=0xee;
long long big ;
big = ((long long) hi ) << 32 | low;

printf("%16x \n ",big);

}

I am lost trying to figure out the mistake i am making.Can you help me
out.Is it compiler dependent?



"%16x"期望一个unsigned int类型的参数。你给它一个类型为long long的

参数。使用%16llx。 (不确定

你的运行时库会支持这个。)


实际上,我可能会使用%016llx获得领先的零。


另外,为什么在\ n之前和之后都有空格?


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http:// www。 ghoti.net/~kst>

诺基亚

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

"%16x" expects an argument of type unsigned int. You''re giving it an
argument of type long long. Use "%16llx". (It''s not certain that
your runtime library will support this.)

Actually, I''d probably use "%016llx" to get the leading zeros.

Also, why do you have spaces before and after the "\n"?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于int64来自int 32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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