Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. 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)

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)

Scheduled Pinned Locked Moved Solved C++ Gurus
2 Posts 2 Posters 772 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1

    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 = 110110

    the result
    0000000000000000010100110101010001010011010001010101011000000110

    I can understand why 110 to the right of bitset is 6 but other bit codes are weird. Why is other digits are they are?

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      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.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved