How to convert character to binary?

How would you convert a given character into a string into the 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 the frame is defined as a byte array (as byte [] in the DataFrame class

+4
source share
2 answers
String binaryString = Integer.toBinaryString(0x100 + bytes[i]).substring(2);
+2
source

try it

        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));
        }
0
source

All Articles