13,097,926 members (57,694 online)
Rate this:
See more:
Hello every body!
I have a hex file save multy objects (call is X).X has fieds:name,month,year and 4 values.
when some one write file, you can see image below. X save in total 3 row,
+First row save name, month,day,year...
+Second row save 4 values (data type is real)
+three row is 0.
I can know first row and three row, but i can't read 4 values of second row.
the bold row is 103.15,103.12,94.66 and 30.06
but when i convert it from hex to decimal then result is incorrect.
I must decrypt to get this values. but i can't know writer how to created it?
what mean of this 4 values?
you can see my picture:
picture
Posted 14-Apr-13 7:19am
Richard MacCutchan 14-Apr-13 13:58pm

Why are you converting it to decimal? The information you have provided looks like a hex dump of a file that contains various different items of information, so converting it to decimal is meaningless. You need to know the exact format of each element of each record and process them in whatever way is necessary to restore them to their original content.

Rate this:

## Solution 1

To convert from decimal to hex, simply try string `hexValue = value.ToString("X");`.
v2
Sergey Alexandrovich Kryukov 14-Apr-13 16:36pm

Correct, a 5.
—SA
Andreas Gieriet 14-Apr-13 18:02pm

I doubt this is the corrent solution. See my comment and my solution below.
Cheers
Andi
Abhinav S 14-Apr-13 22:44pm

Thank you SA.
Andreas Gieriet 14-Apr-13 18:01pm

Sorry for my ignorence, but I think this is not addressing OP's question.
Doesn't he ask for reading binary data (he names them "hex") to to the equivalent in memory (he calls them "decimal").
I read his question that he got that binary file ("[...]someone write file[...]") and need to slurp it into memory and make respective floating values from the mentioned four chunks.
Maybe I'm misinterpreting OP's question.
Cheers
Andi
Rate this:

## Solution 2

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```

- 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
Abhinav S 14-Apr-13 22:45pm

5. Hopefully one of our solutions will be what the OP is looking for.
Andreas Gieriet 15-Apr-13 11:47am

Yes, the question is a bit cryptic an we both read quite the oposite out of it ;-)
Cheers
Andi
PS: have my 5 too ;-)

Top Experts
Last 24hrsThis month
 Graeme_Grant 245 ProgramFOX 115 RickZeeland 105 ppolymorphe 85 Jochen Arndt 65
 OriginalGriff 4,219 Graeme_Grant 2,412 ProgramFOX 2,117 Jochen Arndt 1,860 ppolymorphe 1,820