public static String bin2Hex(String binStr) { int deci = Integer.valueOf(binStr,2); return Integer.toHexString(deci); } public static String hex2Bin(String hexStr) { int deci = Integer.valueOf(hexStr,16); return Integer.toBinaryString(deci); }
public static void main(String args[]) { String str = "f012"; System.out.println(hex2Bin(str)); System.out.println(bin2Hex("01011011")); }
执行结果:
1111000000010010
5b
非常简单
8进制同理,转换
时间: 2024-10-08 03:34:42