__int64到LARGE_INTEGER [英] __int64 to LARGE_INTEGER

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

问题描述

  __ int64  FileSizeDistance =  2711617536 ; 

LARGE_INTEGER liSize;

liSize.LowPart =( int )(FileSizeDistance& 0xFFFFFFFF);
liSize.HighPart =( int )(FileSizeDistance>> 32 );

_tprintf( LowPart:%d,HighPart:%d \ n,liSize.LowPart,liSize.HighPart);

return 0 ;







结果是:



LowPart:-1583349760,HighPart:0



什么是正确的方法?

解决方案

< blockquote>我看到你的编译器支持64位有符号整数。因此,您需要使用 QuadPart 成员来存储该值。



 LARGE_INTEGER liSize; 
liSize.QuadPart = FileSizeDistance;





参见 MSDN [ ^ ]了解详情。



祝你好运!


最简单的是

 liSize.QuadPart = FileSizeDistance; 



您的作业没有错,但是演员应该根据desitination类型(LowPart的 DWORD LONG for HighPart)。甚至您的打印输出也是正确的。要获得预期的输出,只需打印低部分 unsigned

 _tprintf(LowPart:%u,HighPart :%d \ n,liSize.LowPart,liSize.HighPart); 


您的值已正确加载到liSize中,尽管您已经完成了解决方案1演示了一种更简单的方法。您的代码中的问题是打印输出部分。您使用%d作为低阶部分LowPart,但是它是无符号的int。如果您使用%u,您将收到正确的结果。高位部分为0是正确的。


__int64 FileSizeDistance = 2711617536;

LARGE_INTEGER liSize;

liSize.LowPart = (int)(FileSizeDistance & 0xFFFFFFFF);
liSize.HighPart = (int)(FileSizeDistance >> 32);

_tprintf("LowPart:%d, HighPart:%d\n", liSize.LowPart, liSize.HighPart);

return 0;




The result is :

LowPart: -1583349760, HighPart: 0

What is the right way?

解决方案

I see that your compiler has support for 64bit signed integers. So you need to use the QuadPart member to store the value.

LARGE_INTEGER liSize;
liSize.QuadPart = FileSizeDistance;



See MSDN[^] for details.

Good Luck!


The simplest would be

liSize.QuadPart = FileSizeDistance;


Your assignment is not wrong, but the castings should be according to the desitination type (DWORD for LowPart and LONG for HighPart). Even your print output is correct. To get the expected output, just print the low part as unsigned:

_tprintf("LowPart:%u, HighPart:%d\n", liSize.LowPart, liSize.HighPart);


Your value has been correctly loaded into liSize, although you could have done it an easier way, as solution 1 demonstrates. The problem in your code is the print out part. You used %d for the low order part LowPart, which is however an unsigned int. If you use %u instead you will receive the correct result. And it is correct that the high part is 0.


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

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