









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










uses as source
uses as sink
uses as source/sink
uses as source
uses as sink
UTF-
knows ASCIIIf you open a UTF-16 document in a text editor that only Unicode, when encoded as 16-bit characters is called UTF-16.
i t l o o k s l i k e t h i s .
bytes in the Unicode representation of ASCII symbols.The gaps (or squares) bet ween the letters are the zero
characters.identical to ASCII, but it is also able to contain Unicode For documents that only contain ASCII characters, UTF-8 islength encoding was developed called UTF-8.To bridge the gap bet ween ASCII and Unicode, a variable-
How UTF-8 encodes Unicode values:
0 a a a a a a a
0 a a a a a a a
a a b b b b b b
0 0 0 0 0 a a a
1 1 0 a a a a a
1 0 b b b b b b
b b c c c c c c
1 1 1 0 a a a aa a a a b b b b
1 0 b b b b b b
1 0 c c c c c c
Encoding “Hello, World!” in UTF-8:
e2 80 9c
201c 0048 00e9 006c 006c 006f 002c
201d
H é l l o ,
0057 006f 0072 006c 0064 0021 W o r l d!
201c 0048 00e9 006c 006c 006f 002c
201d
H é l l o ,
0057 006f 0072 006c 0064 0021 W o r l d!
Encoding “Hello, World!” in UTF-8:
e2 80 9c
201c 0048 00e9 006c 006c 006f 002c
201d
H é l l o ,
0057 006f 0072 006c 0064 0021 W o r l d!
Encoding “Hello, World!” in UTF-8:
e2 80 9c
c7 a
6c
simplicity, express your answers in hex:Convert the following UTF-16 characters to UTF-8. For
Hex
Binary
0
0
1
1
2
10
3
11
4
100
5
101
6
110
7
111
8
1000
9
1001
A
1010
B
1011
C
1100
D
1101
E
1110
F
1111
Character range
Encoding (binary)
0x007f)
00000000 0bbbbbbb
0bbbbbbb
0x07ff)
00000aaa aabbbbbb
110aaaaa 10bbbbbb
0x0800)
aaaabbbb bbcccccc
1110aaaa 10bbbbbb 10cccccc
0065 046c
47df
Text Within Binary Streams
you want to serialize When you are serializing the state of your objects, sometimes
String
s as well as primitive types.
DataInputStream While we didn't talk about it at the time we discussed
/
, these classes have
methods to support reading and writing
s to and from
dos.writeUTF("string") binary streams.
writes a
to the stream.
reads a
from the stream.
UTF-8 is the only text format available.
the binary stream ends,To be able to determine where the text data embedded in
sends a
(t wo-
UTFFormatException Embedded UTF-8 Strings are limited to 64K, andbytes in the UTF-8 string.byte) value into the stream giving the total number of
is thrown if the String is too long.
is a subclass of
.