Daniel B. answered 09/20/22
PhD in Computer Science with 42 years in Computer Research
Step 1: Convert the Unicode value of 7898 to binary:
1111011011010
which is 13 bits
Step 2: Find minimal number of bytes for the encoding:
If the binary value fits into 7 bits then 1 byte is sufficient (not our case).
If the binary value fits into 11 bits then 2 bytes are sufficient (not our case).
If the binary value fits into 16 bits then 3 bytes are sufficient (our case).
Step 3: Prepare the header bits for each byte:
First byte has header 1110 (the three 1's mean 3 bytes and the 0 terminates the header)
Second byte has header 10 (all bytes after the first one have header 10)
Third byte has header 10 (all bytes after the first one have header 10)
Step 4: Pack the given Unicode bits into the three bytes starting from the back:
The third byte gets the last six bits 011010.
The second byte gets the next six bits 111011.
The first byte gets the rest padded with 0 to fill 4 bits: 0001
(The padding is to 4 bits because the header takes the other 4 bits of the first byte.)
Step5: Put the headers and data together
11100001 10111011 10011010