拿原始的toBinaryString改的 public static void main(String[] args) { System.out.println(toBinaryString(6053)); }
final static char[] digits = {'0','1'};
public static String toBinaryString(int i) { char[] buf = new char[32]; int pos = 32; int mask = 1; do { buf[--pos] = digits[i & mask]; i >>>= 1; } while (pos > 0);
return new String(buf, pos, 32); }
public class Test1 {
public static void main(String[] args) { System.out.println(toFullBinaryString(0x3)); }
public static String toFullBinaryString(int num) { char[] chs = new char[Integer.SIZE]; for(int i = 0; i < Integer.SIZE; i++) { chs[Integer.SIZE - 1 - i] = (char)((num >> i & 1) + '0'); } return new String(chs); } }
public static void main(String[] args) {
System.out.println(toBinaryString(6053));
}
final static char[] digits = {'0','1'};
public static String toBinaryString(int i) {
char[] buf = new char[32];
int pos = 32;
int mask = 1;
do {
buf[--pos] = digits[i & mask];
i >>>= 1;
} while (pos > 0);
return new String(buf, pos, 32);
}
public static void main(String[] args) {
System.out.println(toFullBinaryString(0x3));
}
public static String toFullBinaryString(int num) {
char[] chs = new char[Integer.SIZE];
for(int i = 0; i < Integer.SIZE; i++) {
chs[Integer.SIZE - 1 - i] = (char)((num >> i & 1) + '0');
}
return new String(chs);
}
}