将整数转换为对应的8位二进制字符串
1 /** 2 * 将整数转换为对应的8位二进制字符串 3 */ 4 public static String binaryString(int num) { 5 StringBuilder result = new StringBuilder(); 6 int flag = 1 << 7; 7 for (int i = 0; i < 8; i++) { 8 int val = (flag & num) == 0 ? 0 : 1; 9 result.append(val); 10 num <<= 1; 11 } 12 return result.toString(); 13 }