0

我在理解如何将十六进制值转换为持续时间时遇到问题。

以下是我在研究案例中看到的一些示例:

2b3da = 2:44.986
2bf64 = 2:47.868
2c84a = 2:50.074

有人可以帮助了解这些结果是如何达到的吗?

谢谢。

4

1 回答 1

0
string hex1;
string[] hex = new string[16];
hex[0] = hex1.Substring(0, 2);       
hex[1] = hex1.Substring(2, 2);
hex[2] = hex1.Substring(4, 2);
hex[3] = hex1.Substring(6, 2);
hex[4] = hex1.Substring(8, 2);
hex[5] = hex1.Substring(10, 2);
hex[6] = hex1.Substring(12, 2);
hex[7] = hex1.Substring(14, 2);
//WE DONOT NEED TO REVERSE THE STRING

//CONVERTING TO INT SO WE CAN ADD TO THE BYTE[]
int[] decValue = new int[8];
for (int i = 0; i < 8; i++)
{
    decValue[i] = Convert.ToInt32(hex[i], 16);
}

//CONVERTING TO BYTE BEFORE WE CAN CONVERT TO UTC 
byte[] timeByte = new byte[8];

for (int i = 0; i < 8; i++)
    timeByte[i] = (byte)decValue[i];

    DateTime convertedTime = ConvertWindowsDate(timeByte);
    textBox7.Text = convertedTime.ToString();    
}

public static DateTime ConvertWindowsDate(byte[] bytes)
{
    if (bytes.Length != 8) throw new ArgumentException();
    return DateTime.FromFileTimeUtc(BitConverter.ToInt64(bytes, 0));
}

输入:0060CE5601D6CE01

输出 : 31-10-2013 06:20:48

于 2014-10-10T07:41:42.840 回答