+ 3
Please can someone explain all these operators
& >> << >>>
4 ответов
+ 4
& (bitwise and):
a=5, b=3
a&b:
0101 (5)
0011 (3)
-----
0001
so a&b = 1
~(bitwise compliment)
a = 00110011
~a= 11001100
<<(left shift)
a = 0000 1110
if you use a<<2, the result is:
0011 1000
>>(right shift)
a = 0000 1110
a>>1:
0000 0111
>>> (zero fill right shift)
10111010 >>> 4 = 00001011
if the number is positive, there is no difference between >> and >>>. But if negative,
10111010 >> 4 = 11111011
because the first bit was 1 and fills all of new places with 1
+ 3
and this too ~
+ 3
~ 1000 = 0111
the NOT (~) operator will change 1 to 0 and 0 to 1
but it works with too many bits(32 i think :/ )
5 = 00000000000000000000000000000101
~5 = -6
the first bit (left) sets the sign (-+)
+ 2
does that mean ~10 will equals -11?