提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将整数转换为六位二进制字符串。
/** from nowjava - 时代Java**/ //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { int num = 2; System.out.println(to6BitBinary(num)); } /** * Convert an integer into a six bit binary string. * * @param num The int to convert. * * @return A six character string that represents the int. */ public static String to6BitBinary(int num) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 6; i++) { sb.append(((num & 1) == 1) ? '1' :