查找十进制编码十六进制值的正确公式
我这里有一个案例,我试图弄清楚如何将十六进制数转换为十进制数。
我以前也遇到过类似的情况,但发现如果我反转十六进制字符串,并交换每个第二值(小端),然后将其转换回十进制值,我就得到了我想要的,但这个不同。
这是我们收到的值
Value nr。 1 是 十二月:1348916578 十六进制:0a66ab46
我现在只有这个十进制/十六进制,但我正在尝试获取更多值来比较结果。
我希望任何数学天才都能看到这里使用了什么公式:)
谢谢
I have a case here where I am trying to figure out how a hex number is converted into a decimal number.
I had a similar case before, but found out that if I reversed the hex string, and swapped each second value (little-endian), then converting it back to a decimal value I got what I wanted, but this one is different.
here is the values we received
Value nr. 1 is
Dec: 1348916578
Hex: 0a66ab46
I just have this one decimal/hex for now but I am trying to get more values to compare results.
I hope any math genius out there will be able to see what formula might been used here :)
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因此,如果一个数字是这样的,以十六进制数字表示:
那么可能的转换是:
其中
rev
反转半字节中的位顺序;虽然我可以看到逆转也可以在字节的基础上完成。So, if a number is like this, in hex digits:
Then a possible conversion is:
where
rev
reverses the order of bits in the nibble; though I can see that the reversal could be done on a byte-wise basis also.有趣......我将十进制和十六进制扩展为二进制,这就是您分别得到的:
通过填充一些 0 将底部的一个滑过,然后分成 8 字节块。
看来要开始排队了。让我们让底部看起来像顶部一样。
用 0 填充第一个块,它是相等的。
第二块没问题。
交换第三个块(反转),10101011 变成 11010101。
第四个块也是如此。
10100000 1100110 11010101 01100010
现在它们是相同的。
这适用于所有情况吗?不可能知道。
Interesting.... I expanded the decimal and hex into binary, and this is what you get, respectively:
Slide the bottom one over by padding with some 0s, then split into 8-byte blocks.
It seems to start to line up. Let's make the bottom look like the top.
Pad the first block with 0s and it's equal.
The second block is ok.
Switch the 3rd block around (reverse it) and 10101011 becomes 11010101.
Likewise with the 4th.
10100000 1100110 11010101 01100010
Now they're the same.
Will this work for all cases? Impossible to know.
x0a66ab46 的十进制值为 174500678 或 1185637898(取决于您使用的字节序,以及任何 8、16 或 32 位访问)。这些值之间似乎没有直接联系。也许你只是把这对错了?如果您发布一些有关如何生成这些值对的代码,它可能会有所帮助。
顺便说一句,Delphi 有一个很好的小方法:SysUtils.IntToHex
The decimal value of x0a66ab46 is 174500678 or 1185637898 (depending which endian you use, with any 8, 16 or 32bit access). There seems to be no direct connection between these values. Maybe you just have the pair wrong? It could help if you posted some code about how you generate these value pairs.
BTW, Delphi has a fine little method for this: SysUtils.IntToHex
我们发现,我们的最小 USB 读卡器提供 10 位十进制格式,但实际上并未显示完整的二进制代码。十六进制阅读器找到完整的二进制代码。因此本质上可以通过在二进制转换后去掉 9 个字符来从十六进制值转换为 10 位十进制值。
但反之则不行(除非我们从十六进制值中去掉 2 个字符,否则 10 位十进制代码将仅显示完整二进制代码的一部分)。
所以案子结束了。
What we found was that our min USB reader that gave 10 bit decimal format is actually not showing the whole binary code. The hexadecimal reader finds the full binary code. so essentially it is possible to convert from hexadecimal value to 10 bit decimal by taking off 9 characters after binary conversion.
But this does not work the other way around (unless we strip away 2 characters from the hexadecimal value the 10 bit decimal code will only show part of the full binary code).
So case closed.