我正在尝试通过组合16位和8位值来填充64位无符号变量:
uint8_t byte0 = 0x00;
uint8_t byte1 = 0xAA;
uint8_t byte2 = 0x00;
uint8_t byte3 = 0xAA;
uint16_t hword0 = 0xAA00;
uint16_t hword1 = 0xAAAA;
uint64_t result = ( hword0 << 32 ) + ( byte3 << 24 ) +
( byte2 << 16 ) + ( byte1 << 8 ) + ( byte0 << 0 );
Run Code Online (Sandbox Code Playgroud)
这给了我一个警告。
Run Code Online (Sandbox Code Playgroud)left shift count >= width of type [-Wshift-count-overflow] uint64_t result = ( hword0 << 32 )