I want to write a function to convert a number to 8 bit binary String. For example: with 20, the result I got is 10100, the expected result I want is 00010100.
public static int printBinaryform(int number) {
int remainder;
if (number <= 1) {
System.out.print(number);
return 0;
}
remainder = number % 2;
printBinaryform(number >> 1);
System.out.print(remainder);
return remainder;
}
public static int encryptionNumber(int number, int key) {
int encrrptionNumber = number ^ key;
return encrrptionNumber;
}
with input is 20, I expect the output of 00010100, the actual result is 10100.