Giter Club home page Giter Club logo

Comments (5)

huwenkang99 avatar huwenkang99 commented on June 11, 2024 5

1.base64编码规则:将一个3x8bit的二进制数据转换为4x6bit的二进制数据
例如:11111111,11111111,11111111 切割一下成:111111,111111,111111,111111
再转换为8位的二进制:00111111,00111111,00111111,00111111。
2.所以一个24位的二进制数据转换为了32的数据,增加了(32-24)/24=1/3的长度
所以2M的二进制文件,经过base64编码之后,大小会增加 (2x1024)/3=682.667byte
(由于最后两个8bit的不够编写成一个64位编码对应的 "A"~"/" 之间的字符,就在最后面一个字符为“=”,所以增加683byte)

from fe-interview.

hjx5309 avatar hjx5309 commented on June 11, 2024

2M的二进制文件一共有2097152个字节,而每个字节原本是由8个二进制来表示,base64编码是以6个二进制来表示一个字节,所以原始文件的3个字符就会转化成base64的4个字符,简单公式为3×8/6=4,如果原始文件的字节不是3的倍数,base64就会用0补全,所以,题目中的大小会增减2×8/6-2=0.667M

from fe-interview.

azl397985856 avatar azl397985856 commented on June 11, 2024

2M的二进制文件一共有2097152个字节,而每个字节原本是由8个二进制来表示,base64编码是以6个二进制来表示一个字节,所以原始文件的3个字符就会转化成base64的4个字符,简单公式为3×8/6=4,如果原始文件的字节不是3的倍数,base64就会用0补全,所以,题目中的大小会增减2×8/6-2=0.667M

”base64编码是以6个二进制来表示一个字节“ 这句话不对吧?

from fe-interview.

hjx5309 avatar hjx5309 commented on June 11, 2024

image
是不是应该这么表述,
这是引用https://juejin.im/post/5d206ab1f265da1bcb4f4d21#heading-2

from fe-interview.

azl397985856 avatar azl397985856 commented on June 11, 2024

image
是不是应该这么表述,
这是引用juejin.im/post/5d206ab1f265da1bcb4f4d21#heading-2

这个描述是对的。 你的描述是反的

from fe-interview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.