关于处理进制的工具方法
1:将short类型的十六进制转化为16位的二进制
public static byte toByte(short value, boolean first) {
if (first)
return (byte) (0xff & (value >> 8));
return (byte) (0xff & value);
}
2:将一个十进制数转化为32位的二进制数
public static byte toByte(int value, int pos) {
switch(pos){
case 0:
return (byte) (0xff & (value >> 24));
case 1:
return (byte) (0xff & (value >> 16));
case 2:
return (byte) (0xff & (value >> 8));
case 3:
return (byte) (0xff & value);
default:
return 0;
}
}
3:测试版日志的打印
public static void logPrint(String tag,String msg){
//Constant.ISDEBUG作为一个开关
if(Constant.ISDEBUG){
Log.d(tag,msg);
}
}
4将mac地址的十六进制转化为十进制
public static byte ascTobyte(byte asc) {
byte byteVal = 0;
if (asc >= '0' && asc <= '9')
byteVal = (byte) (asc - '0');
else if (asc >= 'a' && asc <= 'z')
byteVal = (byte) (asc - 'a' + 10);
else if (asc >= 'A' && asc <= 'Z')
byteVal = (byte) (asc - 'A' + 10);
return byteVal;
}