0

I have 3 questions about base64:

1) The base64 encoding purpose is binary-to-text. Isn't text going to be sent through web as binary? Then what is good for?

2) In past they used 7-bit communication systems, now it's 8-bit. Then why we still using it now?

3) How it increases the size? I just take 3-bytes with 28-bit and rearrange them to 4-bytes of 6-bit but in total they still 28-bit?

jps
  • 20,041
  • 15
  • 75
  • 79

1 Answers1

1

1) The purpose is not only binary to text encoding, but also to encode text which uses specific character sets/codepages that go beyond the standard 7 bit ASCII code. In case of binary data you also have the problem that certain values cause problems. A value of 0 in your data could be interpreted as the end of the text, when transmitted in an email or a part of a HTTP Request. On the receiving side, everything after the first 0 might be 'forgotten' and the data would be corrupted. Base64 encoding avoids all the possible problems by encoding everything in a subset of 64 characters which are independent from the actual codepage and don't contain any control characters.

Isn't text going to be sent through web as binary?

Under the hood everything is binary, be it a text, a picture, a movie, the code that is executed, it's all just a bunch of zeroes and ones in the memory and processor registers.

2) see 1)

3) 3 bytes are 3 * 8 bits = 24 bits of information. A base 64 character just represents 6 bits, therefore you need 4 base64 characters 4 * 6 bits = 24 bits to encode the information. But these base64 characters are normal 8 bit characters, so in fact these 4 base64 characters occupy a space of 4 * 8 bits = 32 bits. That's an increse of 33%.

jps
  • 20,041
  • 15
  • 75
  • 79
  • I kinda get it, but regarding point 3 you say that ascii is 8-bit isn't it 7-bit and that's why we used it – yousef elsayed Dec 12 '19 at 10:19
  • @yousefelsayed : Ok, it's a bit sloppy to talk about 8 bit ASCII characters. The original ASCII is 7 bit long and most modern codepages (e.g. ISO-8859-x, Windows-1252, and even UTF-8) use the original ASCII-Codes for the first 128 characters and differ in everything that goes beyond. Nonetheless, when I type an 'A', it usually occupies 8 bits of memory and is coded as '01000001'. – jps Dec 12 '19 at 10:38
  • oh my god i'm losing my mind , if we are taking about 80's or something which communications where 7-bit i convert binary to ascii which is 7-bit but it occupies 8-bit idon't get it. please explain it to me – yousef elsayed Dec 12 '19 at 12:12
  • You might to read about ASCII and the history [here](https://en.wikipedia.org/wiki/ASCII). Nowadays computers work with bytes (8 bit) as the smallest addressable memory unit, so it is obviously most efficient to store one character in one memory cell, even if one bit is "wasted". But the original 7 bit code now only lives on as a subset of the above mentioned codepages and character sets, so 7 bit codes are obsolete anyway. – jps Dec 12 '19 at 12:31