一妻枕、16進(jìn)制與10進(jìn)制轉(zhuǎn)換
public class HexConverterUtil{
public static int convert2Int(String hexString){
Converter<String,Integer> converter;
if (hexString.startsWith("0x")){
converter = from -> Integer.parseInt(from.substring(2), 16);
return converter.convert(hexString);
}else {
converter = from -> Integer.parseInt(from, 16);
return converter.convert(hexString);
}
}
public static String convert2Hex(Integer intValue){
Converter<Integer, String> converter;
converter = from -> Integer.toHexString(from);
String value = converter.convert(intValue);
int len = value.length();
if (value.length() < 8){
for (int i = 0; i < 8 - len; i++) {
value = "0" + value;
}
}
return value;
}
}
@FunctionalInterface
interface Converter<F, T> {
T convert(F from);
}