如何解释使用单字节的最高有效位 - Pcapng 时间格式 "if_tsresol"
How to interpret using Most Significant Bit of single byte - Pcapng time format "if_tsresol"
我正在编写一个库来解析文件格式 (pcapng) documented here。有一个特定的部分我遇到了麻烦,它是一个选项,它定义了应该如何解析 long
epoch/time 变量。根据规范,选项 if_tsresol
由单个 octlet/byte 定义:
The if_tsresol option identifies the resolution of timestamps. If the
Most Significant Bit is equal to zero, the remaining bits indicates
the resolution of the timestamp as a negative power of 10 (e.g. 6
means microsecond resolution, timestamps are the number of
microseconds since 1/1/1970). If the Most Significant Bit is equal to
one, the remaining bits indicates the resolution as as negative power
of 2 (e.g. 10 means 1/1024 of second). If this option is not present,
a resolution of 10^-6 is assumed (i.e. timestamps have the same
resolution of the standard 'libpcap' timestamps).
Example: '6'.
我对这两种情况的工作方式都很满意。例如。首先,如果值为“0”,则表示自 1970 年以来的秒数,“3”表示自 1970 年以来的毫秒数,“9”表示微秒数等。
我对第二种情况也很满意,10 表示它是 1/1024 秒(即接近毫秒),20 意味着 1/1048576 秒(即接近微秒)。
我的困惑在于 "Most Significant Bit",以及如何在这两者之间进行选择。我的理解是 Most Significant Bit 实际上是位序列中最左边的位。
因此,以第一个示例为例,值“3”的位为 00000011
,因此最高有效位等于零,对吗?
但是,在整个字节为 128 或更大之前,第一个有效位不会停止为零,在这种情况下,第二个 'option' 是无意义的,因为我们期望的是 10-30 之间的数字。
我应该忽略字节本身计算中的第一位吗?所以:
00001010 = 10 which is 10 (option 1)
10001010 = 138 which is 10 (option 2)
和
00000110 = 6 which is 6 (option 1)
10000110 = 134 which is 6 (option 2)
Should I be ignoring the first bit in the calculation of the byte itself?
是的。正如 pcapng 规范所说:
If the Most Significant Bit is equal to one, the remaining bits indicates the resolution as as negative power of 2 (e.g. 10 means 1/1024 of second).
所以第一位是标志,其余位是值,计算时忽略第一位。
我正在编写一个库来解析文件格式 (pcapng) documented here。有一个特定的部分我遇到了麻烦,它是一个选项,它定义了应该如何解析 long
epoch/time 变量。根据规范,选项 if_tsresol
由单个 octlet/byte 定义:
The if_tsresol option identifies the resolution of timestamps. If the Most Significant Bit is equal to zero, the remaining bits indicates the resolution of the timestamp as a negative power of 10 (e.g. 6 means microsecond resolution, timestamps are the number of microseconds since 1/1/1970). If the Most Significant Bit is equal to one, the remaining bits indicates the resolution as as negative power of 2 (e.g. 10 means 1/1024 of second). If this option is not present, a resolution of 10^-6 is assumed (i.e. timestamps have the same resolution of the standard 'libpcap' timestamps).
Example: '6'.
我对这两种情况的工作方式都很满意。例如。首先,如果值为“0”,则表示自 1970 年以来的秒数,“3”表示自 1970 年以来的毫秒数,“9”表示微秒数等。
我对第二种情况也很满意,10 表示它是 1/1024 秒(即接近毫秒),20 意味着 1/1048576 秒(即接近微秒)。
我的困惑在于 "Most Significant Bit",以及如何在这两者之间进行选择。我的理解是 Most Significant Bit 实际上是位序列中最左边的位。
因此,以第一个示例为例,值“3”的位为 00000011
,因此最高有效位等于零,对吗?
但是,在整个字节为 128 或更大之前,第一个有效位不会停止为零,在这种情况下,第二个 'option' 是无意义的,因为我们期望的是 10-30 之间的数字。
我应该忽略字节本身计算中的第一位吗?所以:
00001010 = 10 which is 10 (option 1)
10001010 = 138 which is 10 (option 2)
和
00000110 = 6 which is 6 (option 1)
10000110 = 134 which is 6 (option 2)
Should I be ignoring the first bit in the calculation of the byte itself?
是的。正如 pcapng 规范所说:
If the Most Significant Bit is equal to one, the remaining bits indicates the resolution as as negative power of 2 (e.g. 10 means 1/1024 of second).
所以第一位是标志,其余位是值,计算时忽略第一位。