For an assignment I am trying to convert a string into a 7-bit binary. However, we are not allowed to use Integer.toBinaryString(int). This is what I have so far
public static int[] encodeToBit(String str) {
int[] convertString = new int[str.length() * 7];
for (int i = 0; i < convertString.length; i++) {
convertString[i] = (int)str.charAt(i);
for (int j = convertString.length; j >=0 ; j--) {
while (true) {
convertString[i] =
}
}
}
return convertString;
}
Any advice for how to convert an integer ASCII representation of a char into a 7-bit binary.
Edit: For example, encodeToBit(“C") should output the array
[ 1, 0, 0, 0, 0, 1, 1 ]