利用JDK中Integer转换
代码语言:javascript复制 public static int[] valueToBinary(int size, int value) {
String str = Integer.toBinaryString(value);
int[] buffer = new int[size];
int start = buffer.length - str.length();
for (int i = 0; i < str.length(); i ) {
buffer[start ] = Integer.parseInt(str.substring(i, i 1));
}
return buffer;
}