RFC5905 64-bit timestamp format中的fraction的精度为什么是232 picoseconds?

本文详细解释了64位时间戳格式在数据包头和5GQoS监测中的应用,特别关注其32位秒和32位分数部分,可以达到232皮秒的高精度,通过将1秒划分为2^32份实现这种精度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、64bit的Timestamp Format   

The 64-bit timestamp format is used in packet headers and other places with limited word size.  It includes a 32-bit unsigned seconds field spanning 136 years and a 32-bit fraction field resolving 232 picoseconds.                  

    1秒 = 1000毫秒 (millisecond) = 1,000,000微秒(microsecond) = 1,000,000,000纳秒(nanosecond) = 1,000,000,000,000皮秒(picosecond)

2、为什么是232 piposeconds?

从时间单位上看,232picosecond 不到四分之一纳秒,为什么单位这么奇怪,不是微秒、纳秒的倍数?

答案隐藏在附录里:

get_time() 函数返回的tstamp是64-bit的timestamp:

    typedef

要获取服务器上的标准时间,您需要使用网络时间协议(NTP)与时间服务器进行通信。在Unity中,您可以使用NTPClient类从时间服务器获取时间。 以下是一个示例代码片段,演示如何使用NTPClient类获取时间: ``` using System; using System.Net; using System.Net.Sockets; public class TimeManager : MonoBehaviour { public static DateTime GetNetworkTime() { // Time server address const string ntpServer = "pool.ntp.org"; // NTP message size - 16 bytes of the digest (RFC 2030) var ntpData = new byte[48]; // Setting the Leap Indicator, Version Number and Mode values ntpData[0] = 0x1B; // Connect to the time server var addresses = Dns.GetHostEntry(ntpServer).AddressList; var ipEndPoint = new IPEndPoint(addresses[0], 123); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.Connect(ipEndPoint); // Send the NTP request socket.Send(ntpData); // Receive the NTP response socket.Receive(ntpData); // Closing the socket socket.Close(); // Offset to get to the "Transmit Timestamp" field (time at which the reply // departed the server for the client, in 64-bit timestamp format." const byte serverReplyTime = 40; // Get the seconds part ulong intPart = BitConverter.ToUInt32(ntpData, serverReplyTime); // Get the seconds fraction ulong fractPart = BitConverter.ToUInt32(ntpData, serverReplyTime + 4); // Convert From big-endian to little-endian intPart = SwapEndianness(intPart); fractPart = SwapEndianness(fractPart); var milliseconds = (intPart * 1000) + ((fractPart * 1000) / 0x100000000L); // Convert the NTP time to DateTime (1900 -> 1970) var networkDateTime = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds((long)milliseconds).ToLocalTime(); return networkDateTime; } private static uint SwapEndianness(ulong x) { return (uint)(((x & 0x000000ff) << 24) + ((x & 0x0000ff00) << 8) + ((x & 0x00ff0000) >> 8) + ((x & 0xff000000) >> 24)); } } ``` 您可以在需要获取服务器时间的脚本中调用GetNetworkTime()函数,它将返回当前时间的DateTime对象。请注意,此函数需要Internet连接才能与时间服务器通信。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值