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*)§or[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?
精彩评论