字节转换为十六进制方法

package iso;

public class Test5 {  

/**   * @param b  

*     16进制数 转换成字符串形式  

* @return  

*/  

public static String byte2hex(byte[] b) {   

String hs = "";  

 String stmp = "";   

for (int i = 0; i < b.length; i++) {    

stmp = Integer.toHexString(b[i] & 0xFF);    

if (stmp.length() == 1) {     

hs += stmp;    

} else {    

 hs += stmp;    

}   

}   

return hs.toUpperCase();

 }

 public static void main(String[] args) {

  byte[] str1= new byte[]{12,4};

  System.out.println(byte2hex(str1));   

 }

}

posted @ 2013-10-22 16:48  cuifc  阅读(977)  评论(0)    收藏  举报