Richie Thomas
Richie Thomas

Reputation: 3265

How does Base64 convert to ASCII characters?

I'm reading this article on "How Base64 Encoding Works", and I see that Base64 converts each set of 3 8-bit bytes into binary, then convert that binary into 4 groups of 6 bits. Finally, those 4 groups are reassembled back into integers and converted to ASCII characters.

The example given takes the numbers 155, 162 and 233. When converted into binary, the string becomes "10011011 10100010 11101001". Split into 4 equally-sized groups, this is "100110", "111010", "001011", and "101001". Next, the protocol converts these back into ints (38, 58, 11 and 41).

The last step is the one I don't understand. Quoting the article:

These numbers are converted to ASCII characters in the second step using the Base64 encoding table. The 6-bit values of our example translate to the ASCII sequence "m6Lp".

When I look at the ASCII Table, I don't see how this is true. Using the decimal column on the left of each column and the character column on the right of each column, I would have translated [38, 58, 11 41] to ["&", ":", "VT" (vertical tab), ")"]. Even if I use another column besides the left-hand decimal column (i.e. the Hex column), I still don't get the expected result.

I see the table at the bottom of the screen where "m" clearly correlates with 38. But this table is materially different from what the official ASCII table states.

I assume the problem is my lack of familiarity with ASCII conversion rather than an inaccuracy in the article, so what am I doing incorrectly?

UPDATE: they are two different tables. My mistake when asking this question was assuming that a conversion to ASCII implies using the ASCII conversion table, when in fact there's a different table (the Base64 conversion table, which is what the article depicts).

Upvotes: 0

Views: 1877

Answers (1)

Kajbo
Kajbo

Reputation: 1158

You are doing nothing incorrectly. Table used in article to translate binary code to chars is different to your table.

You can recheck it with this nice tool: https://www.rapidtables.com/code/text/ascii-table.html

Upvotes: 1

Related Questions