从十六进制中提取制造日期 [英] Extracting Manufacture date from Hex

查看:133
本文介绍了从十六进制中提取制造日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用SD卡,成功地从ic读取SID到vb.net.Problem来自我需要制造日期的代码。数据表说:

Im working with SD card, succesfuly reading SID from ic to vb.net.Problem comes when i need a code for Manufacture date. Datasheet says:


制造日期由两个十六进制数字组成,一个是8位表示年(y),另一个是表示月(m)的4位。 "m"字段[11:8]是月份代码。 1 = 1月。
"y"字段[19:12]是年份代码。 0 = 2000.例如,生产日期"2001年4月"的日期字段的二进制值将为:00000001 0100。

The manufacturing date is composed of two hexadecimal digits, one is 8 bits representing the year(y) and the other is 4 bits representing the month (m). The "m" field [11:8] is the month code. 1 = January. The "y" field [19:12] is the year code. 0 = 2000. As an example, the binary value of the Date field for production date "April 2001" will be: 00000001 0100.


提到这个并不难,难以创建一个代码将根据十六进制数字放置DateTime。例如,我接收0x00 0xAC [000000000000000010101100]
我们只占12位(前4位保留),意味着[000010101100],前8位是一年0x0A = 10(DEC)= 2010,最后4位是mounth [1100] = 12(DEC),这意味着我们有12.2010生产日期。如何用比特进行这种操作然后
将结果放入DateTime?我通过serialport.readexisting在字符串表示中收到HEX。

Understing this wasnt hard, the hard part is to create a code which will put DateTime according to hex numbers. For example i recevied 0x00 0xAC [000000000000000010101100] we take only 12bits(first 4 is reserved), it means [000010101100], first 8 bits is a year 0x0A = 10(DEC) = 2010, and last 4 bits its a mounth [1100] = 12(DEC), so it means we have 12.2010 Manufacture date. How to do this kind of manipulation with bits then put result into DateTime? I receive HEX in string representation through serialport.readexisting.

推荐答案



我通过serialport.readexisting在字符串表示中收到HEX。

I receive HEX in string representation through serialport.readexisting.

如果输入数据确实是十六进制字符串,那么您需要先转换为整数。 然后,您可以提取每个值的相关部分。 请注意,如果您要创建日期,则必须假设一天。 时间将默认为零。

If that input data really is a hex string then you need to first convert to integer.  Then you can extract the relevant part of each value.  Note that if you want to create a date then you must assume a day.  The time will default to zero.

        Dim S1 As String = "01"
        Dim S2 As String = "4c"

        Dim B1 As Integer = Convert.ToInt32(S1, 16)
        Dim B2 As Integer = Convert.ToInt32(S2, 16)

        Dim Year As Integer = B1 + 2000
        Dim Month As Integer = B2 >> 4
        Dim D As Date = New Date(Year, Month, 1)


这篇关于从十六进制中提取制造日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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