Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 需要帮助在C中将十六进制字符串转换为时间吗#_String_Time_Hex_Type Conversion - Fatal编程技术网

String 需要帮助在C中将十六进制字符串转换为时间吗#

String 需要帮助在C中将十六进制字符串转换为时间吗#,string,time,hex,type-conversion,String,Time,Hex,Type Conversion,我在理解如何将十六进制值转换为持续时间时遇到问题 以下是我在案例研究中看到的一些例子: 2b3da = 2:44.986 2bf64 = 2:47.868 2c84a = 2:50.074 有人能帮助理解这些结果是如何实现的吗 谢谢。字符串hex1; string hex1; string[] hex = new string[16]; hex[0] = hex1.Substring(0, 2); hex[1] = hex1.Substring(2, 2); hex[2] = h

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

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

2b3da = 2:44.986
2bf64 = 2:47.868
2c84a = 2:50.074
有人能帮助理解这些结果是如何实现的吗

谢谢。

字符串hex1;
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));
}
字符串[]十六进制=新字符串[16]; hex[0]=hex1.子串(0,2); hex[1]=hex1.子串(2,2); hex[2]=hex1.子串(4,2); hex[3]=hex1.子串(6,2); hex[4]=hex1.子串(8,2); hex[5]=hex1.子串(10,2); hex[6]=hex1.子串(12,2); hex[7]=hex1.子串(14,2); //我们不需要反转字符串 //转换为INT以便我们可以添加到字节[] int[]decValue=新的int[8]; 对于(int i=0;i<8;i++) { decValue[i]=转换为32(十六进制[i],16); } //在转换为UTC之前先转换为字节 字节[]时间字节=新字节[8]; 对于(int i=0;i<8;i++) timeByte[i]=(byte)decValue[i]; DateTime convertedTime=ConvertWindowsDate(时间字节); textBox7.Text=convertedTime.ToString(); } 公共静态日期时间转换器WindowsDate(字节[]字节) { 如果(bytes.Length!=8)抛出新的ArgumentException(); return DateTime.FromFileTimeUtc(BitConverter.ToInt64(字节,0)); }
输入:0060CE5601D6CE01


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

您能提供任何上下文吗?这些数据来自哪里?这可以是任何类型的自定义编码。可能是,这是通过网络发送的UDP数据包的一部分。它基本上与赛车游戏相关,包含完成时间。有人确实成功地转换了这个(这就是我获得这些结果的原因),但到目前为止我无法联系他。