Matrix 解码十六进制格式
我有十六进制的字符串:Matrix 解码十六进制格式,matrix,hex,transform,decoding,Matrix,Hex,Transform,Decoding,我有十六进制的字符串: “000083F000000000B410D1A9000083FB41051B5000034B410105000083F000000000000000000C05B400000000C006B400000000D07440” 我知道它包含什么: (1,0,-1.192093e-007) (-9.284362e-014,1,-7.788287e-007) (1.192093e-007,7.788287e-007,1) (111222333) 是的,这是一个变换矩阵 解码前7
“000083F000000000B410D1A9000083FB41051B5000034B410105000083F000000000000000000C05B400000000C006B400000000D07440”
我知道它包含什么:
(1,0,-1.192093e-007)
(-9.284362e-014,1,-7.788287e-007)
(1.192093e-007,7.788287e-007,1)
(111222333)
是的,这是一个变换矩阵
解码前72个字符(每个数字8个字符)非常简单,只需按8拆分并使用IEEE浮点格式,即0x000080f=1.0f
因此,我们仍然有“000000000000000000C05B400000000000C06B400000000000D07440”
,其中包含第四个向量,但我从未见过这种数字编码
有什么想法吗?看起来这些是8字节的IEEE浮点数,从字节40开始。因此,布局是:
- 字节0-11:第一个向量,3个单精度数字
- 字节12-23:第二个向量,3个单精度数字
- 字节25-35:第三个向量,3个单精度数字
- 字节36-39:未使用?(填充?)
- 字节40-63:第四个向量,3个双精度数字
(1, 0, -1.192093E-07)
(-9.284362E-14, 1, -7.788287E-07)
(1.192093E-07, 7.788287E-07, 1)
(111, 222, 333)
示例代码:
using System;
class Program
{
static void Main(string[] args)
{
string text = "0000803F00000000000000B4B410D1A90000803FB41051B500000034B41051350000803F000000000000000000C05B400000000000C06B400000000000D07440";
byte[] bytes = ParseHex(text);
for (int i = 0; i < 3; i++)
{
float x = BitConverter.ToSingle(bytes, i * 12);
float y = BitConverter.ToSingle(bytes, i * 12 + 4);
float z = BitConverter.ToSingle(bytes, i * 12 + 8);
Console.WriteLine($"({x}, {y}, {z})");
}
// Final vector
{
double x = BitConverter.ToDouble(bytes, 40);
double y = BitConverter.ToDouble(bytes, 48);
double z = BitConverter.ToDouble(bytes, 56);
Console.WriteLine($"({x}, {y}, {z})");
}
}
// From https://stackoverflow.com/a/854026/9574109
public static byte[] ParseHex(string hex)
{
int offset = hex.StartsWith("0x") ? 2 : 0;
if ((hex.Length % 2) != 0)
{
throw new ArgumentException("Invalid length: " + hex.Length);
}
byte[] ret = new byte[(hex.Length-offset)/2];
for (int i=0; i < ret.Length; i++)
{
ret[i] = (byte) ((ParseNybble(hex[offset]) << 4)
| ParseNybble(hex[offset+1]));
offset += 2;
}
return ret;
}
static int ParseNybble(char c)
{
if (c >= '0' && c <= '9')
{
return c-'0';
}
if (c >= 'A' && c <= 'F')
{
return c-'A'+10;
}
if (c >= 'a' && c <= 'f')
{
return c-'a'+10;
}
throw new ArgumentException("Invalid hex digit: " + c);
}
}
使用系统;
班级计划
{
静态void Main(字符串[]参数)
{
字符串text=“000083F00000000B410D1A9000083FB41051B5000034B410105000083F000000000000000000C05B400000000C006B400000000D07440”;
byte[]bytes=ParseHex(文本);
对于(int i=0;i<3;i++)
{
float x=位转换器.ToSingle(字节,i*12);
float y=位转换器.ToSingle(字节,i*12+4);
float z=位转换器.ToSingle(字节,i*12+8);
WriteLine($“({x},{y},{z})”;
}
//最终向量
{
double x=位转换器.ToDouble(字节,40);
双y=位转换器.ToDouble(字节,48);
双z=位转换器.ToDouble(字节,56);
WriteLine($“({x},{y},{z})”;
}
}
//从https://stackoverflow.com/a/854026/9574109
公共静态字节[]解析十六进制(字符串十六进制)
{
int offset=十六进制起始值,带“0x”)?2:0;
如果((十六进制长度%2)!=0)
{
抛出新ArgumentException(“无效长度:“+hex.length”);
}
字节[]ret=新字节[(十六进制长度偏移)/2];
对于(int i=0;i ret[i]=(byte)((parsenyble(hex[offset])='0'&&c='A'&&c='A'&&c您有任何来自生成值的系统的文档吗?仅限于通知它包含变换矩阵,仅此而已