十六进制二进制字节顺序

huangapple go评论81阅读模式
英文:

HexBinary byte order

问题

关于HexBinary用于XML的第一个Google链接显示指向文章。

这里有一个HexBinary表示的示例:

"<?xml version="1.0" encoding="UTF-8"?>"
"3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f"

但是当我尝试自己实现编码或使用在线转换器时,我得到了下面的字符串:

"3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E"

字节顺序的差异在3f3c和3c3f之间。这不可能是UTF-16的问题,因为它会产生类似于3c003f00或003c003f这样的结果。

因此,我的问题是:这是文章(O'Reilly的书)中的问题,还是xsd:hexBinary有特殊规则要求反转字节顺序?

英文:

The first google link about HexBinary for XML shows link to this article.

There are an example of HexBinary representation:

"<?xml version="1.0" encoding="UTF-8"?>"
"3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f"

But when I try to implement encoding myself or use online converter, I receive next string:

"3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E"

Difference in byte order 3f3c vs 3c3f. It cannot be UTF-16 problem because it will produce something like 3c003f00 or 003c003f.

So, my question: is it problem in article (book from O'Reilly) or there are special rules for xsd:hexBinary which require to invert byte order?

答案1

得分: 1

没有规则告诉你要倒转字节顺序。

XSD hexBinary 数据类型的规范 仅说明:

> hexBinary 表示任意的十六进制编码二进制数据。

注意其中的 任意 - 它并未告诉你如何编码数据,或者在编码完成后是否需要交换每两个字节。

这是书中的一个错误。看起来书的作者可能只是将文本复制粘贴到十六进制编辑器或转换器中,没有注意到在默认设置下,它以 小端序 字节顺序以 2 个字节为单位显示数据。如果你不习惯处理二进制数据,这是一个容易犯的错误。

目前似乎还没有报告这个勘误。如果愿意,你可以在 https://www.oreilly.com/catalog/errata.csp?isbn=9780596004217 提交勘误。

英文:

There are no rules that tell you to invert the byte order.

The XSD specification for hexBinary data type is just:

> hexBinary represents arbitrary hex-encoded binary data.

Note the word arbitrary - it doesn't tell you how to encode the data, or that you need to swap every two bytes after the encoding is done.

This is an error in the book. It seems likely the author of the book just copied and pasted text into a hex editor or converter, and didn't notice that with default settings it displays data in units of 2 bytes in little-endian byte order. This is an easy mistake to make if you're not used to working with binary data.

It doesn't look like this errata has been reported. If you want to, you can submit an errata to https://www.oreilly.com/catalog/errata.csp?isbn=9780596004217

huangapple
  • 本文由 发表于 2020年8月25日 17:27:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63575873.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定