package com.zalk.cn.engTool;
/**
* @author 进制转换
*
*/
public class cons {
@SuppressWarnings("unused")
private long hexTodec(int[] serial) {
// TODO 十六进制转换十进制
long result = 0;
for(int i=(serial.length-1);i>=0;i--) {//从高位到低位
long iserial = serial[i]&0xff;//按位与
long k = iserial<<((3-i)*8);//根据位置进行进位
result+= k;
}
return result;
}
@SuppressWarnings("unused")
private long octTodec(int[] serial) {
// TODO 八进制转换十进制
long result = 0;
for(int i=(serial.length-1);i>=0;i--) {//从高位到低位
long iserial = serial[i]&(077);
long k = iserial<<((3-i)*6);
result+= k;
}
return result;
}
public static void main(String[] args) {
int[] serialH = { 0xE9, 0xA2, 0xE4, 0xF3};
int[] serialO = { 035, 052, 026, 045};
// System.out.println(0xE9A2E4F3&0xffffffff);
System.out.println(new cons().hexTodec(serialH ));
System.out.println(new cons().octTodec(serialO));
}
}