//s为要转换的string,length为要转换成的byte数组的长度
private byte[] getBytes(String s, int length) {
int fixLength = length - s.getBytes().length;
if (s.getBytes().length < length) {
byte[] S_bytes = new byte[length];
System.arraycopy(s.getBytes(), 0, S_bytes, 0, s.getBytes().length);
for (int x = length-fixLength; x < length; x++) {
S_bytes[x] = 0x00;
}
return S_bytes;
}
return s.getBytes();
}
String转指定长度的byte数组,不足位数补0
最新推荐文章于 2024-04-27 18:57:27 发布