Negative logical shift
Posted
by user320862
on Stack Overflow
See other posts from Stack Overflow
or by user320862
Published on 2010-04-20T00:07:59Z
Indexed on
2010/04/20
0:13 UTC
Read the original article
Hit count: 322
In Java, why does -32 >>> -1 = 1 ?
It's not specific to just -32. It works for all negative numbers as long as they're not too big.
I've found that
x >>> -1 = 1
x >>> -2 = 3
x >>> -3 = 7
x >>> -4 = 15
given 0 > x > some large negative number
Isn't >>> -1 the same as << 1? But -32 << 1 = -64.
I've read up on two's complements, but still don't understand the reasoning.
© Stack Overflow or respective owner