package com.xiaopeng.trafficControl.util;
|
|
import com.xiaopeng.trafficControl.DecodingException;
|
import org.apache.commons.codec.DecoderException;
|
import org.apache.commons.codec.binary.Hex;
|
|
|
/**
|
* 与字节16进制相关的工具类<br/>
|
*/
|
public class HexUtil {
|
/** 将十六进制字符串转成字节数组 */
|
public static byte[] toHexBytes(String hexText) {
|
try {
|
return Hex.decodeHex(hexText.toCharArray());
|
} catch (DecoderException e) {
|
throw new DecodingException(e);
|
}
|
}
|
|
/** 将字节数组转成十六进制字符串(字母小写) */
|
public static String toLowerCase(byte[] hex) {
|
return new String(Hex.encodeHex(hex, true));
|
}
|
|
/** 将字节数组转成十六进制字符串(字母大写) */
|
public static String toUpperCase(byte[] hex) {
|
return new String(Hex.encodeHex(hex, false));
|
}
|
|
/** 将字节数组转成整数 */
|
public static int hashToInt(byte[] hash) {
|
return (int) (hash[3] << 24 | hash[2] << 16 | hash[1] << 8 | hash[0]);
|
}
|
|
}
|