views:

731

answers:

6

I'm a bit curious as to why one would want to use hex encoding over base64. It seems to me that base 64 is more efficient. In particular, why is it that databases seem to always use hex encoding? Is it a historical issue, or am I missing something about hex encoding?

+3  A: 

You must be a real geek to read BASE64 off the screen.

In Oracle, when I run HEXTORAW, I can get some idea of what's in a RAW field, but I couldn't with BASE64.

Like, when I see lots of 0x3F's, I know there's something with encoding.

And internally, these are just binary bytes, there is no other need to encode them but to show to a person on the other side of the screen.

Quassnoi
You would only need to convert it to base64 if you need to send somewhere over ASCII, to be decoded back to binary and used.
Osama ALASSIRY
A: 

I would imagine your database is really storing the data as binary, but the query editor will show it using hex encoding. This is what SQL Server Query Analyzer will do.

David
A: 

I guess it is just a matter of personal preference... Hex is by far easier for me to read then something in Base32 or Base64

Polaris878
+1  A: 

It is a good compromise between efficient space usage and readability. Bit patterns become very apparent in hex, while other bases aren't as clear.

which is easier to read, 0x8080 or 32896? I would say the hex value is.

It also has the nice property of each hex digit being equal to a nibble (therefore each pair equal to a byte).

It is far easier to make sense of hex in your head than base 64.

As far as the database, well keep in mind that there is a difference between how data is displayed and how it is stored. It is most likely simply displaying the data as hex.

Evan Teran
+1  A: 

Base64 doesn't work if you want to use the resulting values as filenames on Windows, because base64 uses both uppercase and lowercase letters. I'm sure there are other times when it can't be used for similar reasons.

Agree with other answers regarding readability - hex digits align nicely on 8-bit bytes, while base64 "digits" do not, and one digit can contain parts of two bytes.

romkyns
A bit of a corner case, but a good reason not to use base64 all the same.
Jason Baker
+1  A: 

In the case of string storage (with "potentially" XML safe encoding) your could gain even more efficiency with ASCII 85 as it is a 5/4 bloat instead of 4/3 for base64.

But it is even harder to "read" then base64. And not many applications support it so often you have to write your own classes/functions to do the encoding and decoding.