+ 2
which is the rule for binary shifting of a negative number
example -7 >> 3
8 Respuestas
+ 2
it works quite simple:
y<<x is equivalent y*2**x
y>>x is equivalent y//2**x
(so -7//2**3 == -7//8 == -1 (floor division))
+ 4
In which language?
All language is different about this
+ 3
7=
0000 0000
0000 0000
0000 0000
0000 0111
-7=
1111 1111
1111 1111
1111 1111
1111 1001
negative just flip all bits and do addition by one
-7>>3=
0001 1111
1111 1111
1111 1111
1111 1111
Sorry I might be wrong bc I'm busy
[Edited]
-7>>3=
1111 1111
1111 1111
1111 1111
1111 1111
shift in negative will fill 1 instead 0
+ 3
Actually the >> right bit shift is pretty standard across multiple languages.
The right bit shift shifts the binary value of x to the right y times (x >> y) dropping off the right most value of the binary number and left fills a copy of the left most number.
I.E.
A positive number is 0 (zero) filled on the left while a negative number is 1 (one) filled from the left.
a 16 bit binary number with the value of -10 would look like:
1111 1111 1111 0110
so if we right shifted it 2 times it would look like:
1111 1111 1111 1101
which has the value of -3
if we right shifted it 2 more times:
1111 1111 1111 1111
we now have -1. At this point it won't matter how many times we right shift, the value will not go any higher than -1
+ 2
how do i have to calculate it (language = pencil).
+ 2
so i calculate -7 >> 3 = -1
great stuff . i undetstand.
+ 2
so
47>>3 = 5
and
-47>>3 = -6
+ 2
yuri... it is indeed quiet simple!