为什么需要Base64编码&为什么需要二进制转16进制

为什么需要Base64编码

来源于知乎大佬的文章

Base64编码跟Hex区别

计算机中任何数据都是 ASCII 码存储的, ascii 是 128-255 之间的不可见字符。
在网络上进行数据交换,从 A 到 B, 往往要经过多个路由器,
不同设备之间对字符的处理方式有一些不同,不可见字符有可能被错误处理,是不利于传输的,
因此要先做一个 base64 编码,变成可见字符,便于传输

英文解析

When you have some binary data that you want to ship across a network, 
you generally don't do it by just streaming the bits and bytes over the wire in a raw format. 
Why? because some media are made for streaming text. 
You never know -- some protocols may interpret your binary data as control characters (like a modem), 
or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination (like how FTP translates line endings). 
So to get around this, people encode the binary data into characters. Base64 is one of these types of encodings. 
Why 64? Because you can generally rely on the same 64 characters being present in many character sets, and you can be reasonably confident that your data's going to end up on the other side of the wire uncorrupted.

Base64 编码后,解码能得到原本数据

为什么需要二进制转16进制

一切“字符”都必定用数字+编码表表示

ASCII编码表
GB2312编码表
UNICODE让全世界都说一种语言

原本数据二进制转成16进制,再从16进制转回原数据,是可以互转的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章