I am trying to declare an integer in bytes. What i mean is : i am trying to declare int a = 4 as int a = 0100(i have shortened it here to 4 bits for simplicity. ) Following is the code which i have used and is giving me unexpected output.
public class class4A_d {
public static void main(String[] args) {
System.out.println("Hello world,this is the main function ");
int q1= 00000100; //8 bits
int q2 = 00000000000000000000000000000100; //32 bits
System.out.println("q1 and q2 are respectively "+ q1 + ":" + q2); //q1= 64,q2 =64
}
}
I know java stores integers as 32 bits number in 2,s complement in the back end with weight of each bit progressing in the following manner: 2(^0),2(^1),2(^2).....etc. But here it seems that the weights are in the following manner : 8(^0),8(^1),8(^2).....etc. Can anyone explain this ?