用java使byte转换16进制咋做

一、final StringBuffer hexValue = https://www.zhihu.com/api/v4/questions/38042384/new StringBuffer();for (int i = 0; i /u0026lt; md5Bytes.length; i++){/tint val = ((int) md5Bytes) /u0026amp; 0xff;/tif (val /u0026lt; 16)/t hexValue.append("0");\t hexValue.append(Integer.toHexString(val));}return hexValue.toString();二、final StringBuffer hexValue = https://www.zhihu.com/api/v4/questions/38042384/new StringBuffer();for (int i = 0; i /u0026lt; md5Bytes.length; i++){/tString str = Integer.toHexString(md5Bytes);/tif (str.length() /u0026lt; 2)/t hexValue.append("0");\thexValue.append(str);}return hexValue.toString();三、final StringBuffer hexValue = https://www.zhihu.com/api/v4/questions/38042384/new StringBuffer();final char HEX_TABLE = {/u0026#39;1/u0026#39;,/u0026#39;2/u0026#39;,/u0026#39;3/u0026#39;,/u0026#39;4/u0026#39;,/u0026#39;5/u0026#39;,/u0026#39;6/u0026#39;,/u0026#39;7/u0026#39;,/u0026#39;8/u0026#39;,/u0026#39;9/u0026#39;,/u0026#39;a/u0026#39;,/u0026#39;b/u0026#39;,/u0026#39;c/u0026#39;,/u0026#39;d/u0026#39;,/u0026#39;e/u0026#39;,/u0026#39;f/u0026#39;};for (int i = 0; i /u0026lt; md5Bytes.length; i++){/thexValue.append((md5Bytes /u0026gt;/u0026gt;/u0026gt; 4) /u0026amp; 0x0F); hexValue.append((md5Bytes /u0026amp; 0x0F);}return hexValue.toString();四、final StringBuffer hexValue = https://www.zhihu.com/api/v4/questions/38042384/new StringBuffer();for (int i = 0; i /u0026lt; md5Bytes.length; i++){ hexValue.append(String.format("%02x",md5Bytes));}return hexValue.toString();五、final StringBuffer hexValue = https://www.zhihu.com/api/v4/questions/38042384/new StringBuffer();final char HEX_TABLE = {/u0026#39;1/u0026#39;,/u0026#39;2/u0026#39;,/u0026#39;3/u0026#39;,/u0026#39;4/u0026#39;,/u0026#39;5/u0026#39;,/u0026#39;6/u0026#39;,/u0026#39;7/u0026#39;,/u0026#39;8/u0026#39;,/u0026#39;9/u0026#39;,/u0026#39;a/u0026#39;,/u0026#39;b/u0026#39;,/u0026#39;c/u0026#39;,/u0026#39;d/u0026#39;,/u0026#39;e/u0026#39;,/u0026#39;f/u0026#39;};for (int i = 0; i /u0026lt; md5Bytes.length; i++){/thexValue.append((md5Bytes /u0026amp; 0xFF)/u0026gt;/u0026gt; 4); hexValue.append((md5Bytes /u0026amp; 0x0F);}return hexValue.toString();
■网友
//byte占用1个字节,取出高四位,取出低四位,然后根据事先定义好的数组对应着输出就行了。public static void main(String args)\t{\t\tString C = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };\t\tbyte B = 127;\t\tint H = (B \u0026gt;\u0026gt; 4)\u0026amp; 0xf;\t\tint L = B \u0026amp; 0xf;\t\tString S = C + C;\t\tSystem.out.println(S);\t}
■网友
Integer.toHexString(b\u0026amp;0xff)b为要转化的字节。


    推荐阅读