对二进制数据进行十六进制编码的目的是什么?

发布于 2024-07-24 05:38:21 字数 107 浏览 6 评论 0原文

我有点好奇为什么要使用十六进制编码而不是 Base64。 在我看来,base 64 效率更高。 特别是,为什么数据库似乎总是使用十六进制编码? 这是历史问题,还是我遗漏了有关十六进制编码的内容?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

提笔落墨 2024-07-31 05:38:21

您必须是一个真正的极客才能从屏幕上读取 BASE64

Oracle 中,当我运行 HEXTORAW 时,我可以了解 RAW 字段中的内容,但我无法使用 BASE64

就像,当我看到很多 0x3F 时,我就知道有编码的问题。

在内部,这些只是二进制字节,不需要对它们进行编码,只需向屏幕另一侧的人显示即可。

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.

夏九 2024-07-31 05:38:21

这是有效空间利用和可读性之间的良好折衷。 位模式在十六进制中变得非常明显,而其他基数则不那么清晰。

0x8080 和 32896 哪个更容易阅读? 我会说十六进制值是。

它还有一个很好的特性,即每个十六进制数字都等于一个半字节(因此每一对等于一个字节)。

在头脑中理解十六进制比 64 进制要容易得多。

就数据库而言,请记住数据的显示方式和存储方式之间存在差异。 它很可能只是将数据显示为十六进制。

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.

谁与争疯 2024-07-31 05:38:21

如果您想在 Windows 上使用结果值作为文件名,则 Base64 不起作用,因为 Base64 同时使用大写和小写字母。 我确信还有其他时候由于类似的原因它无法使用。

同意有关可读性的其他答案 - 十六进制数字在 8 位字节上很好地对齐,而 base64“数字”则不然,并且一个数字可以包含两个字节的部分。

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.

悲念泪 2024-07-31 05:38:21

在字符串存储(使用“潜在”XML 安全编码)的情况下,使用 ASCII 85 可以获得更高的效率,因为它是 5/4 的膨胀,而不是 base64 的 4/3。

但它比 Base64 更难“读取”。 并且没有多少应用程序支持它,因此您经常必须编写自己的类/函数来进行编码和解码。

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.

成熟的代价 2024-07-31 05:38:21

我想您的数据库实际上将数据存储为二进制,但查询编辑器将使用十六进制编码显示它。 这就是 SQL Server 查询分析器将要做的事情。

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.

め七分饶幸 2024-07-31 05:38:21

我想这只是个人喜好的问题...对于我来说,十六进制比 Base32 或 Base64 更容易阅读

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文