I want to send or store a huge binary file, which must be encoded as text.
Which would be the faster encoding method between hex
encoding and base64
encoding?
The data is around 40 MB or more, which is why the performance matters.
The difference between Base64 and hex is really just how bytes are represented. Hex is another way of saying "Base16". Hex will take two characters for each byte - Base64 takes 4 characters for every 3 bytes, so it's more efficient than hex.
Base64 is commonly used in cryptography to exchange keys. A form of base64 is also used to pass arbitrary data as part of a URI. Thankfully, encoding and decoding base64 is fast.
Base64 and Hex are just two different representations of the same value. Base64 uses more characters and therefore the representation is shorter.
Although Base64 is a relatively efficient way of encoding binary data it will, on average still increase the file size for more than 25%. This not only increases your bandwidth bill, but also increases the download time.
The time spent on the encoding itself isn't really the issue. Base64 is more complex, but the encoding will still not be a large overhead. The real issue is the time spent on transmitting the data over the network, which depends on the encoded size of the data.
Base64 expands the size of data compared to its binary form by one third. So your 40 MB file will be about 53 MB.
Hex encoding doubles the size of the data, so your 40 MB file will be 80 MB.
In short, Base64 wins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With