i'm just trying to make a decimal to binary converter in java, what i want to display is suppose to be like this:
Binary 41 is 00101001
But, here's display what i just made:
Binary 41 is: 101001
And here's my code:
public void convertBinary(int num){
int binary[] = new int[40];
int index = 0;
while(num > 0){
binary[index++] = num % 2;
num/=2;
}
for(int i = index-1; i >= 0; i--){
System.out.print(binary[i]);
}
What can i do, to make a display 8 bit binary? I appreciate it so much for all answer you gave to me, thank you