If I placed 00 or 0 before digits values in array output become different.
int arr[][]=new int[3][2];
arr[0][0]=00;
arr[0][1]=01;
arr[1][0]=10;
arr[1][1]=0011;
arr[2][0]=0020;
arr[2][1]=21;
for(int a[]: arr){
for(int c : a){
System.out.println(c);
}
}
Output is : 0 1 10 9 16 21
so number starting with 0 is octal in java???... because java accepts it as an octal value, So 010 = 8.
I understand bitwise OR operator but why "010" equals 8? It's definitely not compliment 2's notification, so how to decode this number? That is an octal literal ! More specifically : 1*8^1 + 0*8^0 = 8 !
Explanation: The value '\012' means the character with value 12 in octal, which is decimal 10. Note: It is equivalent to char a = 012 and int a = '\012' and int a = 012.
A number with a leading zero is treated as Octal.
Your 0011 is octal 8 + 1 = 9, 0020 is 2 * 8 = 16.
Note that your 00 and 01 are also being interpreted in Octal but they just happen to be the same value as their decimal counterparts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With