Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 vs HEX for sending binary content over the internet in XML doc

Tags:

java

xml

What is the best way of sending binary content between system inside an XML document

I know of Base64 and Hex, what is the real difference. I am currently using Base64 but need to include an external commons library for this where as with HEX I think I could just create a function.

like image 944
jax Avatar asked Jul 06 '10 06:07

jax


People also ask

Is Base64 more efficient than hex?

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.

Why use Base64 instead of binary?

Also, textual media may reject certain binary values as non-text. Base64 encoding encodes binary data as values that can only be interpreted as text in textual media, and is free of any special characters and/or control characters, so that the data will be preserved across textual media as well.

What is the difference between Base64 and binary?

Base64 image representation can be directly placed within html to render an image. Binary takes up less space. And benefits from greater network effects and standardization. E.g. if you want to use amazon simple secure storage S3 you have to store a binary file.

Can Base64 encode binary file?

Base64 encoding is a popular technique to convert data in different binary formats to a string of ASCII characters. This is useful when transmitting data to networks or applications that cannot process raw binary data but would readily handle text.


1 Answers

You could just write your own method for Base64 as well... but I'd generally recommend using external, well-tested libraries for both. (It's not like there's any shortage of them.)

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. Assuming you're using UTF-8 to encode the XML document, a 100K file will take 200K to encode in hex, or 133K in Base64. Of course it may well be that you don't care about the space efficiency - in many cases it won't matter. If it does matter, then clearly Base64 is better on that front. (There are alternatives which are even more efficient, but they're not as common.)

like image 125
Jon Skeet Avatar answered Sep 27 '22 17:09

Jon Skeet