ähm… das “00001000” wär doch als Byte ne Hex08, oder nicht.
Irgendwie versteh ich die Frage nicht.
jo, und
Byte b = Byte.parseByte(a,2);
System.out.println(b);```
spuckt auch ne 8 aus.
*** Edit ***
ansonsten hätt ich das wohl etwa so gemacht:
```public static byte[] binString2ByteArray(String binString) {
int nbyte = binString.length()/8 ;
byte[] bytes = new byte[nbyte];
for (int i = 0; i < nbyte; i ++) {
bytes** = Byte.parseByte(binString.substring(i*8,(i+1)*8), 2);
}
return bytes;
}```
*** Edit ***
oweh, Byte ist ja in Java signed und von daher kann Byte.parseByte.. mit "11111111" wenig anfangen.
man könnt dann bytes** = (byte) Integer.parseInt(binString.substring(i*8,(i+1)*8), 2); machen das ist halt dann mit Vorzeichen, blöd eigentlich, dann wird aus 255 ne -1.
Ich hatte von Byte jedenfalls ne andere Vorstellung..