public class TypeConvert {
/* 字符串转byte[]
这个方法转换后的结果是会多一些 48字符进来的就是代表的是0不知道为什么,但是可以只是取出指定的字符串就行了
*/
public static byte[] stringTo16Byte(String temp) {
int len = temp.length();
for (int i = 0; i < 16 - len; i++) {
if (temp.length() == 16) {
break;
}
temp = temp + "0";
}
return temp.getBytes();
}
/* byte转short */
public final static short getShort(byte[] buf, boolean asc, int len) {
short r = 0;
if (asc)
for (int i = len - 1; i >= 0; i--) {
r <<= 8;
r |= (buf[i] & 0x00ff);
}
else
for (int i = 0; i < len; i++) {
r <<= 8;
r |= (buf[i] & 0x00ff);
}
return r;
}
/* B2 -> 0xB2 */
public static int stringToByte(String in, byte[] b) throws Exception {
if (b.length < in.length() / 2) {
throw new Exception("byte array too small");
}
int j=0;
StringBuffer buf = new StringBuffer(2);
for (int i=0; i
buf.insert(0, in.