Tuesday, April 13, 2010

ASCII to Base64

In data encoding, text are translated into ASCII code to be stored into computers. ASCII code ranges from decimal 1-255. When transferring the data over the network, these data will be translated into binary which is represented by 8 bits. These binary codes will then be converted into Base64 encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that is designed to deal with textual data.

Base64 implementation uses A–Z, a–z, 0–9, ‘+’ and ‘/’.

The following table shows the conversion process from text content to base64 encoding.


Row 1: Actual text data given - ‘Man’

Row 2: Textual data ‘Man’ is converted into ASCII which is the data representation in computer.

Row 3: The ASCII is then converted into binary which formed into 8 bits (8 bits= 1 byte). The three alphabets (letter ‘M’, ‘a’ and ‘n’) makes up to 3 bytes which totaled up to 24 bits altogether.

Row 4: Base64 uses only 64 characters, which is equivalent to 26. This means that 6 bits is to be used for base64 encoding. Hence, 24 bits has to be divided into 6 bits each, makes up to 4 sets of 6 bits. The index is summed up from the 6 bits.

Row 5: The index is converted into base64 encoding according to Base64 index table as per below: