Try the following:
int value = Integer.parseInt("0101011", 2);
Then the bitmap in value will correspond to the binary interpretation of the string "0101011" . Then you can write the value to the file as byte (provided that the string contains no more than 8 binary digits).
EDIT You can also use Byte.parseByte("0101011", 2); . However, byte values ββin Java are always signed. If you tried to parse an 8-bit value with the 8 th bit set (for example, "10010110" , which is 150 decimal), you will get a NumberFormatException because the values ββabove +127 are not suitable in byte . If you don't need to process bit patterns more than "01111111" , then Byte.parseByte works just as well as Integer.parseInt .
Recall, however, that to write a byte to a file, you use OutputStream.write(int) , which takes the value int (not byte ) - although it only writes one byte. You can also go with an int value to start with.
source share