package fromDecimalToBinary;
import java.util.Arrays;
public class mainClass {
public static void main(String args[]) {
System.out.println(Arrays.toString(Binary()));
}
private static int[] Binary() {
int decimal = 123;
int[] arr = new int[8];
for (int i = 0; decimal > 1; i++) {
arr[i] = decimal % 2;
decimal = decimal / 2;
}
for (int k = 8; k > 1; k--) {
if (arr[8] == 1) break;
if (arr[k] == 1) {
arr[k + 1] = 1;
break;
}
}
for (int d = 0; d <= 3; d++) {
int t = arr[d];
arr [d] = arr [8 - (d + 1)];
arr [8 - (d + 1)] = t;
}
return arr;
}
}
Ошибка: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at fromDecimalToBinary.mainClass.Binary(mainClass.java:23)
at fromDecimalToBinary.mainClass.main(mainClass.java:8)