Alex McAfee Alex McAfee - 6 months ago 35
Java Question

Java prints 00010 as 8

having this issue with a decryption program I am writing in Java. Here is the code in question

public static int int_to_int(int input)
{
int[] value_array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26};
int[]bin_array= {00000, 00001, 00010, 00011,
00100, 00101, 00110, 00111,
01000, 01001, 01010, 01011, 01100,
01101, 01110, 01111, 10000, 10001,
10010, 10011, 10100, 10101, 10110,
10111, 11000,11001, 11010, 11011};
for(int i=0; i <27; i++)
{
System.out.println("hello");
if(input==value_array[i])
{
System.out.println("returning: " + bin_array[i] + "at: " + i);
return bin_array[i];
}

}
return -1;
}


And here is the issue highlighted in a line

double temp = 00010;
System.out.println("returning: " + temp);


This will output

returning: 8


but I want to see

returning: 00010


thoughts?

Answer

The 00010 is octal number, i.e., 8. Remove all the leading zeroes.

Comments