如何转换的64位长的数据类型为16位数据类型 [英] How to Convert 64bit Long Data Type to 16bit Data Type

查看:558
本文介绍了如何转换的64位长的数据类型为16位数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何转换 64位长数据类型到任何的 16位数据类型。此功能在以太网应用需要包括在时间戳。只有 2字节 16位)可用来包括时间戳。但是,我们得到 64位长赢API时间戳值。因此,从64位数据类型为16位数据类型的转换是必要的。

I would like to know how to convert 64 bit long Data Type to any of the 16 bit Data Types. This feature is required in the Ethernet Application to include the Time Stamp. Only 2 Bytes ( 16 bits ) are available to include the Time Stamp. But we are getting 64 bit long as the Time Stamp value from Win API. So a conversion from 64 bit data type to to 16 bit data type is essential.

推荐答案

好了,你可以不适合64位信息入库的16位不失一些信息。

Well, you can't fit 64 bits of information into 16 bits of storage without losing some of the information.

所以,就看你如何量化或截断时间戳。例如。假设你在纳秒precision时间戳,但你只需要将其存储在秒precision。在这种情况下,您可以通过10亿除以64位的号码,只剩下秒。那么它可能适合16位或不(16位只会存储多达65535秒)。

So it's up to you how to quantize or truncate the timestamp. E.g. suppose you get the timestamp in nanosecond precision, but you only need to store it at seconds precision. In that case you divide the 64 bit number by 1000000000 and are left with the seconds. Then it might fit into 16 bits or not (16 bits would only store up to 65535 seconds).

如果它不适合,那么你就必须时间戳回绕周期性。这又可能是你的情况有问题,也可能是没有问题的。

If it won't fit, then you'll have the timestamp wrapping around periodically. Which, again, might be a problem in your case or it might be not a problem.

在任何情况下,如果你需要的界面,需要时间戳现有的库 - 弄清楚的什么的它在需要时间戳(时钟滴答秒钟年??)。然后找出在Windows次函数,您正在使用的回报。然后将Windows时间单位转换成库 - 即,您使用的时间单位。

In any case, if you need to interface an existing library that requires timestamps - figure out what it needs in that timestamp (clock ticks? seconds? years?). Then figure out what the Windows times function that you're using returns. Then convert the Windows time unit into the-library-that-you-use time unit.

这篇关于如何转换的64位长的数据类型为16位数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆