M
Mike
Hi, I'm testing the unsigned shift operator in Java. Unfortunately, the
value I predicted for the output is 2^17 (131072), not 2^17 - 1
(131071). See below:
"""
class unsignedshift {
public static void main(String args[])
{
int a = -10;
String bs1;
a = a >>> 15;
bs1 = Integer.toBinaryString(a);
System.out.println(bs1);
System.out.println("The length of the binary string is " + bs1.length());
System.out.println("a = " + a);
}
}
"""
Output is:
"""
11111111111111111
The length of the binary string is 17
a = 131071
"""
Where is the difference of one coming from?
Thanks.
value I predicted for the output is 2^17 (131072), not 2^17 - 1
(131071). See below:
"""
class unsignedshift {
public static void main(String args[])
{
int a = -10;
String bs1;
a = a >>> 15;
bs1 = Integer.toBinaryString(a);
System.out.println(bs1);
System.out.println("The length of the binary string is " + bs1.length());
System.out.println("a = " + a);
}
}
"""
Output is:
"""
11111111111111111
The length of the binary string is 17
a = 131071
"""
Where is the difference of one coming from?
Thanks.