Java 十进制转二进制
利用JDK中Integer转换
java
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;
}
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;
}