Base64 vs HEX用于在XML doc中通过Internet发送二进制内容 [英] Base64 vs HEX for sending binary content over the internet in XML doc

查看:165
本文介绍了Base64 vs HEX用于在XML doc中通过Internet发送二进制内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XML文档中的系统之间发送二进制内容的最佳方式是什么

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

我知道Base64和Hex,真正的区别是什么。我目前正在使用Base64但需要包含一个外部公共库,因为我和HEX一样,我想我可以创建一个函数。

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.

推荐答案

您也可以为Base64编写自己的方法......但我通常建议使用外部的,经过良好测试的库。 (这并不像它们有任何不足。)

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.)

Base64和hex之间的区别实际上就是字节的表示方式。 Hex是另一种说Base16的方式。十六进制将为每个字节占用两个字符--Base64每3个字节需要4个字符,因此它比十六进制更有效。假设您正在使用UTF-8对XML文档进行编码,那么100K文件将需要200K以十六进制编码,或者在Base64中编码为133K。当然,你可能不关心空间效率 - 在很多情况下它并不重要。如果确实重要,那么显然Base64在这方面更好。 (有些替代方案效率更高,但它们并不常见。)

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.)

这篇关于Base64 vs HEX用于在XML doc中通过Internet发送二进制内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆