Write to Your Note Don’t learn it then forget it.
Bitwise Shift Operators
This operators are often forgotten, but by using this operator will save memory and is more secure, especially on game programming and encryption techniques.
Bitwise Shift Right operator “>>”
64 >> 1, then 64 is converted into a binary number 1000000 then shifted 1 bit to the right to be 100000, so 64 >> 1 = 32. To facilitate recall x >> n then any shift to the right then x will be divided by 2 n
64 >> 1 = 32, because 64: 2 = 32
64 >> 2 = 16, because 64: 2: 2 = 16
64 >> 3 = 8, because 64: 2: 2: 2 = 8
63 >> 1 this would mean 63: 2 = 31, the result is an integer
Bitwise Shift Left operator “<<“
To the left is the opposite of the slide slide right
8 ‘<<‘ 1 then 8 is converted into a binary number to 1000. Then do the shift by 1 bit to the left. So that original 1000 will be 10000 (at the time of shifting the rightmost value is filled with bits 0)
8 ‘<<‘ 1 = 16 for 8 x 2 = 16
8 ‘<<‘ 2 = 32 for 8 x 2 x 2 = 32
8 ‘<<‘ 3 = 64 for 8 x 2 x 2 x 2 = 64
Bitwise Shift Operators Zero Fill “>>>”
Leftmost bit (high-order bit) is used to determine the sign (sign) of a number (whether positive or negative). Bit value of 0 indicates a positive value and a bit value of 1 indicates a negative value. Example: Continue reading