What will be in memory uint64_t(6) | (uint64_t('V') << 8) | (uint64_t('E') << 16) | (uint64_t('S') << 24) | (uint64_t('T') << 32) | (uint64_t('S') << 40)
Solved
C++ Gurus
-
I can not explain why this bitwise operation results following bitset in memory.
#include <iostream> #include <bitset> int main(int , char **) { std::bitset<64> bitRepresentation { uint64_t(6) | (uint64_t('V') << 8) | (uint64_t('E') << 16) | (uint64_t('S') << 24) | (uint64_t('T') << 32) | (uint64_t('S') << 40) }; std::cout << bitRepresentation; return 0; }
where
V = 56 = 111000
E = 45 = 101101
S = 53 = 110101
T = 54 = 110110the result
0000000000000000010100110101010001010011010001010101011000000110
I can understand why
110
to the right of bitset is6
but other bit codes are weird. Why is other digits are they are? -
Hi @Kofr,
It looks right to me.
0000000 00000000 01010011 01010100 01010011 01000101 01010110 00000110 - - S T S E V int(6)
The first 16 bits are all 0, because you set nothing in those bits. The next 5 bytes are ASCII chars
STSEV
, and the final byte is integer 6.V = 56 = 111000
Actually, V = 0x56 = 86 (decimal) = 01010110.
Cheers.