Originally posted by Kiran Chand Panga:
class TEST1
{
public static void main(String[] args) {
byte x=3, y=5;
System.out.println((-x == ~x+1) + ","+(-y == ~y+1));
}
}
This is simply
testing that in order to form the negative of a number you flip the bits and add 1.
class TEST2
{
public static void main(String[] args) {
byte x=127;
x<<=2;
System.out.println(x);
}
}
Basically this is shifting 2 0s onto the end of the bits 01111111. When you do this you get 11111100. This is -4.
class TEST3
{
public static void main(String[] args) {
byte y=5;
System.out.println(y<<33);
}
}
Before the shift operation is carried out, we mod 33 by 32. So we are shifting 1 bit.
So we get 10.