Base64 encoding increases the data size by 33.4%

Source: Internet
Author: User

When byte [] is converted to a base64 encoded string through convert. tobase64string, the data volume increases significantly. Why? The answer is in base64 encoding.

Base64 encoding uses 64 basic ASCII characters to re-encode the data. More specifically, the data to be encoded is split into byte arrays, with three bytes as a group. Sort the 24-bit data in order and divide the 24-bit data into four groups, that is, 6-bit data in each group. Then, add two zeros before the highest bits in each group to make up one byte. In this way, a 3-byte data is reencoded into 4 bytes. When the number of bytes of the data to be encoded is not an integer multiple of 3, that is to say, the last group is not three bytes long. At this time, the last group is filled with 1 to 2 bytes of 0. Add 1 to 2 "=" at the end after the final encoding ".

The base64 sequence table is:

Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 +/

According to the above encoding rules, after base64 encoding, the original three bytes will become four bytes, that is, the data volume is increased by 33.3%, plus the following Bytes:

Base64 encoding increases the data size by 33.4%

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.