Hexdump:在字节和双字节小数之间转换

问题描述 投票:1回答:1

当我在没有选项的文件上使用hexdump时,我得到十六进制字节的行:

cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00

当我在同一个文件中使用hexdump -d时,相同的数据显示在称为双字节小数组的内容中:

64207   65261   00007   00256   00003   32768   00002   00000

所以我想弄清楚的是如何在这两种编码之间进行转换。小数点上的cffa分别是207250。这些数字是如何结合起来制作64207的?

奖金问题:使用这些分组有什么好处?八进制显示使用16个三位数组,为什么不使用十进制显示相同的东西?

byte hexdump radix
1个回答
0
投票

由@georg评论。

0xfa * 256 + 0xcf == 0xfacf == 64207

转换完全像这样。

所以,如果你看到man hexdump

-d, --two-bytes-decimal
              Two-byte decimal display.  Display the input offset in hexadecimal, followed by eight
              space-separated,  five-column, zero-filled, two-byte units of input data, in unsigned
              decimal, per line.

所以,例如:

00000f0   64207   65261   00007   00256   00003   32768   00002   00000

这里,00000f0是十六进制偏移量。

接着是两个字节的输入数据单元,例如:十进制的64207(前16位 - 即文件的两个字节)。

转换(在您的情况下):

cf fa ---->两个字节的单位(byte ordering取决于你的架构)。

fa * 256 + cf = facf ---->恰当----> 0xfacf(重新订购)

oxfacf的dec是64207

额外问题:使用三位数(不同于十六进制和十进制)显示八进制数是一种惯例,因此它对每个字节使用三元组。

© www.soinside.com 2019 - 2024. All rights reserved.