如何解密十六进制到十进制? [英] How to decrypt hex to decimal?

查看:112
本文介绍了如何解密十六进制到十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有一个hex文件保存multy对象(调用X).X有fieds:名称,月份,年份和4个值。

当有人写一个文件时,你可以看到下面的图片。 X共保存3行,

+第一行保存名称,月,日,年...

+第二行保存4个值(数据类型为实数)

+三行是0.

我可以知道第一行和第三行,但我不能读第二行的4个值。

粗体行是103.15,103.12,94.66和30.06

但是当我将它从十六进制转换为十进制时结果是不正确的。

我必须解密才能得到这个值。但我不知道作家如何创造它?

这4个值的意思是什么?

你可以看到我的照片:

图片

推荐答案

要从十进制转换为十六进制,只需try string hexValue = value.ToString(X);
To convert from decimal to hex, simply try string hexValue = value.ToString("X");.


使用C# BitConverter [ ^ ] class。

Eg
Use C# BitConverter[^] class.
E.g.
static void Main(string[] args)
{
    {
        byte[] b = { 0x00, 0x00, 0x00, 0xE0, 0x97, 0xA5, 0x61, 0x40, };
        double d = BitConverter.ToDouble(b, 0);
        Console.WriteLine("from file: {0,-20} = {1}", d, b.Aggregate("", (s, x) => s += " 0x" + x.ToString("X02")));
    }
    {
        double d = 103.15;
        byte[] b = BitConverter.GetBytes(d);
        Console.WriteLine("double:    {0,-20} = {1}", d, b.Aggregate("", (s, x) => s += " 0x" + x.ToString("X02")));
    }
    {
        float d = 103.15f;
        byte[] b = BitConverter.GetBytes(d);
        Console.WriteLine("float:     {0,-20} = {1}", d, b.Aggregate("", (s, x) => s += " 0x" + x.ToString("X02")));
    }
}



以上结果是:


The result of the above is:

from file: 141.174789428711     =  0x00 0x00 0x00 0xE0 0x97 0xA5 0x61 0x40
double:    103.15               =  0x9A 0x99 0x99 0x99 0x99 0xC9 0x59 0x40
float:     103.15               =  0xCD 0x4C 0xCE 0x42



请注意:没有一种模式符合您的描述:

- 第一个条目将第一个字节转换为 double :141.17 ...(不是103.15,因为你声称这将是)。

- 其他两个条目将103.15转换为 double 浮动分别为字节...(不是预期的)。



似乎你对103.15的索赔是错误的,或者存储的数据不是标准的conformat浮点数或......?



干杯

Andi


Please note: none of the patterns match your description:
- The 1st entry converts the first bytes into a double: 141.17... (not 103.15 as you claim this would be).
- The other two entries convert 103.15 as double and float respectively into bytes... (not as expected).

It seems that either your claim for 103.15 is wrong, or the stored data is not a standard conformat floating point number or ...?

Cheers
Andi


这篇关于如何解密十六进制到十进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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