Created
September 16, 2015 14:03
-
-
Save joshbc/aa0ff12c54e1b0463349 to your computer and use it in GitHub Desktop.
unsigned char array to long conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef int32_t LONG; | |
const unsigned char* pData[4]; | |
int pReadIndex = 0; | |
//unsafe | |
LONG *p_long = reinterpret_cast< LONG (&)[4] >( pData[pReadIndex] ); | |
//safe | |
LONG aLong = reinterpret_cast<LONG>(pData[pReadIndex++]) | | |
reinterpret_cast<LONG>(pData[pReadIndex++]) << 8 | | |
reinterpret_cast<LONG>(pData[pReadIndex++]) << 16 | | |
reinterpret_cast<LONG>(pData[pReadIndex++]) << 24; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment