Slide 8
Slide 8 text
(Character) Encoding - String to Bytes
Python
In [40]: c = chr(0x20ac)
In [41]: c
Out[41]: '€'
In [42]: c.encode('utf-8')
Out[42]: b'\xe2\x82\xac'
Java
jshell> String str = new String(Character.toChars(0x20ac))
str ==> "€"
jshell> import java.nio.charset.*
jshell> byte bytes[] = str.getBytes(StandardCharsets.UTF_8)
bytes ==> byte[3] { -30, -126, -84 }
jshell> for (byte b: bytes) { System.out.printf("%x ", b); }
e2 82 ac