public static void enterText(String plaintext ) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Plaintext: ");
plaintext = in.nextLine();
int plaintextLenght = plaintext.length();
int[] array1 = new int[plaintextLenght];
int[] array2 = new int[plaintextLenght];
StringBuilder quoBinary = new StringBuilder();
StringBuilder remBinary = new StringBuilder();
for(int i = 0; i < plaintext.length() ; i++) {
char character = plaintext.charAt(i);
int ascii = (int) character;
array1[i]= ascii / 10;
array2[i] = ascii % 10;
for(int j = 0; j < 8; j++) {
**quoBinary.append((array1 & 128) == 0 ? 0 : 1);
array1<<= 1;
remBinary.append((array2 & 128) == 0 ? 0 : 1);
array2<<= 1;**
}
}
System.out.println("Quotient = "+ Arrays.toString(array1)); // Print array for quotients
System.out.println("Remainder = "+ Arrays.toString(array2)); // Print array for quotients
System.out.println("Binary QQ " + quoBinary);
System.out.println("Binary RR " + remBinary);
}
错误消息:
Bad operand types for binary operator ‘&’
First type: int[]
Second type: int
我无法按位排列一个具有int的数组。
答案 0 :(得分:0)
如果您想转换为ASCII则。 遍历字符串
for(int i = 0 ; i < str.length() ; i++){
char character = str.charAt(i);
System.out.print((int)character);
}