Web Technology Basics
3,000 bytes of image data are encoded with Base64 and embedded in HTML. If no line breaks are inserted, which of the following is the number of characters after encoding?
- A2,250 characters
- B4,000 characters
- C6,000 characters
Show answer and explanation
Answer: B. 4,000 characters
Base64 splits every 3 bytes (24 bits) into four 6-bit groups and represents each with one of 64 characters. The size therefore becomes 4/3 of the original, 3,000 ÷ 3 × 4 = 4,000 characters. When the number of original bytes is not a multiple of 3, "=" is added at the end to fill out a 4-character unit. Embedding an image in HTML or CSS reduces the number of requests, but the data becomes about 33% larger, and the browser can no longer store it as a separate file and reuse it.
- A. This multiplies by 3/4 instead of 4/3.
- B. Correct. 3,000 ÷ 3 × 4 = 4,000 characters.
- C. This is the number of characters when each byte is written as two hexadecimal characters.