进制转换
程序员文章站
2022-07-13 13:17:25
...
转十六进制
public static void main(String[] arg) {
String assIdNum ="54";
byte[] intArr = assIdNum.getBytes();
BigInteger b = new BigInteger(intArr);
String assid = "0x"+b.toString(16);
return assid;
}
public PageInfo formatAssId(PageInfo pageInfo) {
/*
* 转换ID为10进制显示
*/
if(pageInfo !=null){
List baseList = pageInfo.getSearchResult();
List sonList = new ArrayList();
List newList = new ArrayList();
byte[] assIdArr = null;
if (baseList !=null && baseList.size()>0) {
for(int i=0 ; i<baseList.size(); i++) {
sonList = (List)baseList.get(i);
assIdArr = null;
String s = (String)sonList.get(11);
if (s.indexOf("x") !=-1) {
String str = s.substring(s.indexOf("x")+1);
int len = str.length();
String[] strArr = new String[len/2];
assIdArr = new byte[len/2];
int index = 2;
for (int n=0; n<strArr.length; n++){
strArr[n] = str.substring(index*n,index*n+2);
byte assId = Byte.parseByte(strArr[n], 16);
assIdArr[n] = assId;
}
}
String assId = "";
if (assIdArr !=null && assIdArr.length>0 ) {
for (int j=0; j<assIdArr.length; j++) {
char c = (char)assIdArr[j];
assId += Character.toString(c);
}
}
if (! "".equals(assId)) {
sonList.set(11, assId);
}
newList.add(sonList);
}
}
if (newList !=null && newList.size()>0) {
pageInfo.setSearchResult(newList);
}
}
return pageInfo;
}
上一篇: 使用POI实现Excel的导出功能
下一篇: 进制转换