How do you get a decimal number in memory?

output the converted decimal number in each binary number in memory (four bytes in total, each byte separated by a space)
decimal number: 122

binary number: 00000000 00000000 00000000 00001100
Code:
for (int I = 31; I > = 0; iMel -)

{
    std::cout << ((num >> i) & 0x1);//num 
    if (i % 8 == 0)
    {
        std::cout << " ";
    }
}

what does the above code mean? Could you explain it in detail? If anti-code knowledge is involved, please explain it in detail. Why this can be the binary number in memory, thank you!

Jun.02,2022

it is recommended to buy a textbook on computer principles to learn from scratch


in fact, the code is easy to explain. num > > I means to move the binary of num to the right I bit, giving you an example

for example, num = 1011 , that is, decimal 11 , move 1 bit to the right is 0101 , right 2 bit 0010 , right 3 bit 0001 , this is the meaning of >

do & operation on 0x1 , because 0x1 is equivalent to binary 00.01 , and there is only 1 at the end, so the for cycle is equivalent to taking all the binary bits of num , such as moving the first right 31 bit, that is, moving the highest bit to the end, and then carrying out & with 1 . Then move the 30 bit to the right, which is equivalent to moving the second highest bit to the end. Then print it out, and output a space for each 8 bit printed.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32671-2ab56.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32671-2ab56.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?