/**
* 将byte数组转换成16进制字符串
* @param m
* @return
*/
public static String bytetohexString(byte [] m)
{
String hex = "";
String ret = "";
for (int i = 0; i < m.length; i++) {
hex = Integer.toHexString(m[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
ret += hex;
}
return ret;
}
/**
* 数据中地址顺序高地位颠倒,正确顺序地址的16进制字符串
* @param m
* @return
*/
public static String righorderhexString(byte [] m)
{
String hex = "";
String ret = "";
m = rightorder(m);
for (int i = 0; i < m.length; i++) {
hex = Integer.toHexString(m[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
ret += hex ;
}
return ret;
}
/**
* 将地址转换成10进制,方便地址跳转
* @param m
* @return
*/
public static int bytearraytoint(byte[] m )
{
String a = righorderhexString(m);
int b = 0;
int temp;
for (int i = 0; i < a.length(); i++) {
b += Integer.parseInt(a.substring(i, i+1), 16) * adecimal(a.length()-1-i,16);
}
return b;
}
public static int wipeblank(String str )
{
String temp = "";
byte [] s = {00};
String string = "";
try {
string = new String(s,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
int b = 0;
for (int i = 0; i < str.length(); i++) {
if(!str.substring(i, i+1) .equals(string)){
temp += str.substring(i, i+1);
}
}
for (int j = 0; j < temp.length(); j++) {
b += Integer.parseInt(temp.substring(j, j+1), 16) * adecimal(temp.length()-1-j,10);
}
return b;
}
/**
* 幂次数
* @param data
* @param scale
* @return
*/
public static int adecimal(int data , int scale)
{
int a = 1;
for (int j = 1; j <= data; j++) {
a *= scale;
}
return a;
}
/**
* 地址颠倒顺序
* @param addr
* @return
*/
public static byte [] rightorder(byte [] addr)
{
byte [] temp = new byte[addr.length];
for (int i = 0; i < addr.length; i++) {
temp[temp.length-1-i] = addr[i];
}
return temp;
}
分析.pin文件时,用到的几个自定义函数
最新推荐文章于 2023-04-01 09:45:00 发布