Reputation: 3898
How would you convert a given character in a string to a its corresponding binary value?
public void send(DataFrame frame) {
String bitString = frame.toString();
for (int a = 0; a < bitString.length(); a++) {
char c = bitString.charAt(a);
????
}
}
where frame is defined to be a byte array (as byte [] in the DataFrame class
Upvotes: 4
Views: 20064
Reputation: 1993
String binaryString = Integer.toBinaryString(0x100 + bytes[i]).substring(2);
Upvotes: 3
Reputation: 3140
try this
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));
}
Upvotes: 0