Android 转换
发布时间:2018-02-01 来源:查字典编辑
摘要:C#里面的byte[]是这样的传输到Android是List["161","180","122","120","161","180"]如何把...
C# 里面的byte[] 是这样的
传输到Android是 List< String > ["161","180","122","120","161","180"]
如何把 这个字符串转换成对等C#里的 byte[]
回复讨论(解决方案)
String[] array = new String[list.size()];
list.toArray(array);
//字符序列转换为16进制字符串 private String bytesToHexString(byte[] src) { StringBuilder stringBuilder = new StringBuilder("0x"); if (src == null || src.length < = 0) { return null; } char[] buffer = new char[2]; for (int i = 0; i < src.length; i++) { buffer[0] = Character.forDigit((src[i] > > > 4) & 0x0F, 16); buffer[1] = Character.forDigit(src[i] & 0x0F, 16); System.out.println(buffer); stringBuilder.append(buffer); } return stringBuilder.toString(); }
private byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) < < 4) + Character.digit(s.charAt(i + 1), 16)); } return data; }