Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

As far as I know, the unsigned right shift operator inserts a 0 in the leftmost. Below is the code I’ve:

System.out.println(Integer.toBinaryString(-1>>>30))

Output: 11

But when I do the below: 

System.out.println(Integer.toBinaryString(-1>>>32))

Output: 11111111111111111111111111111111

Can anyone tell me why it’s not zero?

1 Answer

0 votes
by (19.7k points)

See this documentation here

When the right-hand operand was subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x1f (0b11111). The shift distance is in the range 0 to 31, inclusive.

Here -1 >>> 32 is equivalent to -1 >>> 0 and -1 >>> 33 is equivalent to -1 >>> 1 and, -1 >>> -1 is equivalent to -1 >>> 31

Interested in Java? Check out this Java tutorial by Intellipaat. 

Related questions

0 votes
1 answer
asked Feb 22, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 31, 2019 in Java by noah kapoor (5.3k points)
0 votes
1 answer
asked Nov 26, 2019 in Java by Nigam (4k points)
0 votes
1 answer

Browse Categories

...