Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Translation of floating point numbers in hex and back.

Author
Message
Absent
15
Years of Service
User Offline
Joined: 25th Oct 2010
Location: Rossia, Rostov-on-Don
Posted: 25th Oct 2010 13:50
has a numeric in series

4,209429E-38 -> 0.000 0000 000.0 0010 0000 0000 0000 0000 -> 00;02;00;00
8,418858E-38 -> 0.000 0000 000.0 0100 0000 0000 0000 0000 -> 00;04;00;00
1,262829E-37 -> 0.000 0000 000.0 0110 0000 0000 0000 0000 -> 00;06;00;00
1,683772E-37 -> 0.000 0000 000.0 1000 0000 0000 0000 0000 -> 00;08;00;00
2,104715E-37 -> 0.000 0000 000.0 1010 0000 0000 0000 0000 -> 00;0A;00;00
2,525658E-37 -> 0.000 0000 000.0 1100 0000 0000 0000 0000 -> 00;0C;00;00
2,9466E-37 -> 0.000 0000 000.0 1110 0000 0000 0000 0000 -> 00;0E;00;00
3,367543E-37 -> 0.000 0000 000.1 0000 0000 0000 0000 0000 -> 00;10;00;00
3,788486E-37 -> 0.000 0000 000.1 0010 0000 0000 0000 0000 -> 00;12;00;00
4,209429E-37 -> 0.000 0000 000.1 0100 0000 0000 0000 0000 -> 00;14;00;00
4,630372E-37 -> 0.000 0000 000.1 0110 0000 0000 0000 0000 -> 00;16;00;00
5,051315E-37 -> 0.000 0000 000.1 1000 0000 0000 0000 0000 -> 00;18;00;00
5,472258E-37 -> 0.000 0000 000.1 1010 0000 0000 0000 0000 -> 00;1A;00;00
5,893201E-37 -> 0.000 0000 000.1 1100 0000 0000 0000 0000 -> 00;1C;00;00
6,314144E-37 -> 0.000 0000 000.1 1110 0000 0000 0000 0000 -> 00;1E;00;00

I know there is a format IEEE 754,
where for a single float exponent = 8 bytes
in my case, exponent = 10 bytes
I need a formula for the transfer of
(6,314144 E-37) in hexadecimal format (00; 1E; 00; 00)

help me?

P.S. Apologies for the translation
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Oct 2010 17:33
Hi,

I have no clue how you got those binary representations.
What's your bias? Is it of base 2? How did you calculate the mantissa?

I first assumed your bias was 511 or 512 because you chose 10 bits for the exponent. I soon realized it wasn't, because 2^-511 ~ 10^-154 and your numbers are ~10^-38 while the exponent is 0 in your binary representation.

Secondly, if you were working with base 2, then 4.209429E-38 (your first example number) should be a power of (1/2) since there's only one bit = 1 in the binary representation. So you should have: 4.209429E-38 = (1/2^3) * 2^(0 - BIAS)
Unfortunately, the closest I could get was:
(1/2^3) * 2^(0-121) = 4.7019774E-38

So where it all comes down to is:
Could you give some more information on the format you're using?

Sven B

Absent
15
Years of Service
User Offline
Joined: 25th Oct 2010
Location: Rossia, Rostov-on-Don
Posted: 26th Oct 2010 11:29
Therein lies my problem.
There is a program that takes data
hex of modules for monitoring transport
and writes them into ms sql database.
Simulating the packet from the module and reading the data from the database,
I have the opportunity to compare the result with the input data.

Submitting to the input of a sequence, I concluded that
exponent = 10 bytes

Absent
15
Years of Service
User Offline
Joined: 25th Oct 2010
Location: Rossia, Rostov-on-Don
Posted: 26th Oct 2010 13:04
forgot to say that this data is geographic coordinates.

47.23558 -> 0FD4C33D -> 0.0001111111.001001100001100111101
39.73822 -> 0FCC6355 -> 0.0001111110.011000110001101010101
my city

In the monitoring module which sends the data,
installed GPS-chip SiRFstar III.


http://www.usglobalsat.com/downloads/SiRF_Binary_Protocol.pdf
In the description of a binary protocol chip SiRFstar III says:

Latitude 4S Bytes In degrees (+ = North) x 10 ^ 7
Longitude 4S Bytes In degrees (+ = East) x 10 ^ 7

But I'm not sure that this data directly from the chip
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Oct 2010 17:04
Hi Absent,

This falls outside my knowledge. Raw GPS data is not your conventional encrypted data. But it seems that the internet contains quite some information on how to read GPS data (SIRF).

Cheers!
Sven B

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Oct 2010 21:57
What you are telling us here:
Quote: "Latitude 4S Bytes In degrees (+ = North) x 10 ^ 7
Longitude 4S Bytes In degrees (+ = East) x 10 ^ 7"


Sounds likes it's a signed integer value, simply multiplied by 10000000, which means that your number of 47.23558 north is stored as 472355800, except that the 4 byte hex number you list immediately afterwards doesn't match that at all (it's equivalent to 265601853).

TBH, after taking a short look at the PDF you linked to, I'm not sure that you know exactly what you are asking for, but I am pretty sure you are asking in the wrong place.

You need to ask someone who uses that system to provide you some example code for X86 processors (which will likely be written in C or C++), then ask someone here to use that to assist you to write DBPro code.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Oct 2010 09:50
This is mostly guess work but the format looks a little familiar. I don't think the binary and hex are representing a conversion of the decimal values but rather they are describing the type of data and/or perhaps indexing it as it is being received.

I think for the first series you posted, the values are the decimal value of the data, then a binary position indicator and then a hex position indicator:

4,209429E-38 -> 0.000 0000 000.0 0010 0000 0000 0000 0000 -> 00;02;00;00
8,418858E-38 -> 0.000 0000 000.0 0100 0000 0000 0000 0000 -> 00;04;00;00

4,209429E-38 the data
.0 0010 0000 0000 binary position indicator
00;02;00;00 hex represenation of the binary position with grouping

The second set of data is similar:
47.23558 -> 0FD4C33D -> 0.0001111111.001001100001100111101

47.23558 the data
0FD some kind of position marker + a parity
4C33D hexidecimal notation of the last section of binary

000111111 1 = 0FD where the binary value is 000111111 and the parity is 01
.00100 = 4
11000011 = c3
00111101 = 3d

Enjoy your day.
Absent
15
Years of Service
User Offline
Joined: 25th Oct 2010
Location: Rossia, Rostov-on-Don
Posted: 24th Jan 2011 13:57
Problem solved, all thanks for the help.

Here's the solution if you're interested,
everything is simple,
the first two bits are not used the rest are computed:

Login to post a reply

Server time is: 2026-07-16 10:54:00
Your offset time is: 2026-07-16 10:54:00