开发者

bitwise operation and stuffing bytes together

is there a easy way to form a long long variable from 8 consecutive bytes....

TotalSectors = sector[0x28]|
               sector[0x28+1] << 8 |
               sector[0x28+2] << 16 |
               sector[0x28+3] << 24 |
               sector[0x28+4] << 32 | 
               sector[0x28+5] << 40 |
               s开发者_StackOverflow中文版ector[0x28+6] << 48 |
               sector[0x28+7] << 56;

Where TotalSectors is a long long variable....

I am working on windows platform and win32 api is my main choice..... any existing macro for this work would be helpful....

Thanks in advance...


Endianness is good. So just cast:

 TotalSectors = *(long long*)&sector[0x28];


what about a for loop?

for (int i = 0; i < 8; ++i)
  TotalSectors |= sector[0x28+i]<<(8*i);


I think you have already written the easy way out, so why not simply make it an inline function?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜