标签:for math class byte ret vat java private length
/**
* 将整数转换为byte数组并指定长度
*/
private static byte[] intToBytes(int a, int length) {
byte[] bs = new byte[length];
for (int i = bs.length - 1; i >= 0; i--) {
bs[i] = (byte) (a % 0xFF);
a = a / 0xFF;
}
return bs;
}
/**
* 将byte数组转换为整数
*/
private static int bytesToInt(byte[] bs) {
int a = 0;
for (int i = bs.length - 1; i >= 0; i--) {
a += bs[i] * Math.pow(0xFF, bs.length - i - 1);
}
return a;
}
标签:for math class byte ret vat java private length
原文地址:https://www.cnblogs.com/quchunhui/p/11811293.html