Convert between byte arrays and hexadecimal strings
发布时间
阅读量:
阅读量
package com.example.demo.im;
public class ByteUtils {
private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/** * 方法四:byte[]-->hexString
* * @param bytes
* @return
*/
public static String toHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
// 使用String的format方法进行转换
for (byte b : bytes) {
Integer value = b & 0xff;
sb.append(String.format("%02x", va
全部评论 (0)
还没有任何评论哟~
