日期:2014-05-19 浏览次数:20937 次
BigInteger target = new BigInteger("2828718396"); System.out.println(target.toString(16)); System.out.println(Long.toHexString(2828718396l));
------解决方案--------------------
public static void main(String[] args) { int a = 527461410; int a1 = (a & 0xff); int a2 = ((a >> 8) & 0x00ff); int a3 = ((a >> 16) & 0x00ff); int a4 = ((a >> 24) & 0x00ff); System.out.println(byteToHex(a1) + byteToHex(a2) +byteToHex(a3) +byteToHex(a4)); } /** * byte转换为十六进制字符串 * * @param b * byte * @return 转换后十六进制字符串 */ public static String byteToHex(int b) { char b01 = getChar((b & 0xf0) >> 4); char b02 = getChar(b & 0x0f); return String.valueOf(b01) + String.valueOf(b02); } /** * 取得16进制字符串 * * @param b * 16进制的数字表示 * @return 16进制的char * @throws IllegalArgumentException * 如果非16进制的数字则抛出该异常 */ public static char getChar(int b) { if (b >= 0 && b <= 9) { return (char) ('0' + b); } if (b >= 10 && b <= 15) { return (char) ('A' - 10 + b); } throw new IllegalArgumentException("error byte:" + b); }
------解决方案--------------------
楼主,你的10进制数和16进制数不相等,那你的真实意图是什么呢?
正常Java中10进制和16进制转换是比较简单的,如
long b = Long.parseLong("2828718396");
System.out.println(Long.toHexString(b));
不过结果应该是
a89ad13c