Codeschnipsel zum Thema Char Bytes
- Umwandlung in Byte
- Darstellung der Byte von Char in Binärwerte
- Darstellung der Byte von Char in Textform
- Umwandlung in Byte
- Darstellung der Byte von Char in Binärwerte
- Darstellung der Byte von Char in Textform
Java:
public static byte[] chartoBytes(char c) {
return new byte[]{(byte)((c >> 8)&0x00FF),(byte)(c)} ;
}
public static char bytestoChar(byte b1, byte b2) {
char c1 = (char)(((b1&0x00FF)<<8) + (b2&0x00FF));
return c1 ;
}
//Anzeige von Char als Binärzahl
System.out.println("Char as Byte als Binärwerte. 1.Byte:"+ Integer.toBinaryString(b1 & 0xff) +" 2.Byte:"+Integer.toBinaryString(b2 & 0xff));
//Anzeige von Char als Test
System.out.println("Char as Byte inTextform . 1.Byte:"+ Integer.toString(b1 & 0xff) +" 2.Byte:"+Integer.toString(b2 & 0xff));