如何将字符串中的给定字符转换为其对应的二进制值?
public void send(DataFrame frame) {
String bitString = frame.toString();
for (int a = 0; a < bitString.length(); a++) {
char c = bitString.charAt(a);
????
}
}
其中frame被定义为字节数组(在DataFrame类中作为byte []
答案 0 :(得分:2)
String binaryString = Integer.toBinaryString(0x100 + bytes[i]).substring(2);
答案 1 :(得分:0)
试试这个
String bitString = frame.toString();
for (int a = 0; a < bitString.length(); a++) {
byte[] b = new byte[1024];
b = bitString.getBytes();
System.out.println(Arrays.toString(b));
}