Author Topic: Converter binary double to decimal.  (Read 2354 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 241
Converter binary double to decimal.
« on: February 05, 2019, 07:31:24 PM »
123 82 149   98   55   49 27 65     -->   445517.8462
    2 69 211 172 177 213 89 65     --> 6771539.4103

1     2   3     4     5    6    7   8

how did this conversion? No need to program just explain briefly.


OK.

Rod

  • Newt
  • Posts: 185
Re: Converter binary double to decimal.
« Reply #1 on: February 05, 2019, 10:31:35 PM »
I couldn't leave this at I don't know. So I worked it out

Following on from http://www.theswamp.org/index.php?topic=54889.0

(123 82 149 98 55 49 27 65) to 445517.846238412
Double precision floating point 64 bit number to decimal

reverse the list
convert each decimal to binary
strcat the lot together
you get

01000001 00011011 00110001 00110111
01100010 10001100 01010010 10000001

The first digit is the sign, 0 for positive 1 for negative
The next 11 sigits is the exponent 10000010001 convert this to decimal which is 1041 then - 1023 to get the exponent = 18
The last 52 digits is the mantissa 1011001100010011011101100010100011000101001010000001 you must append this with a "1." (including the decimal point) at the front so that it is actually 1.1011001100010011011101100010100011000101001010000001
convert this is decimal so that it is 1.69951570983280952909 then times it by 2 to the power of the exponent 2^18 = 262144
1.66... x 262144 = 445517.846238412

Finally got there

Cheers, Rod


« Last Edit: February 05, 2019, 10:44:07 PM by Rod »
"All models are wrong, some models are useful" - George Box

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Converter binary double to decimal.
« Reply #2 on: February 06, 2019, 12:43:13 AM »
Nice work Rod, was only reading about this today when it popped up in a news feed http://fabiensanglard.net/floating_point_visually_explained/index.php
which also lead to another good explanation from the comments for those interested - https://www.youtube.com/watch?v=pQs_wx8eoQ8

When I read the OP I was a bit unsure until you pointed out the first digit was the sign bit :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

FELIX

  • Bull Frog
  • Posts: 241
Re: Converter binary double to decimal.
« Reply #3 on: February 06, 2019, 09:59:11 AM »
Excellent ROD, now it's easy to convert the coordinates that are in binary.
For more than 40 years I have not worked with binary numbers but it's like cycling, we lose practice but not balance.
OK.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Converter binary double to decimal.
« Reply #4 on: February 06, 2019, 10:08:15 AM »
For more than 40 years I have not worked with binary numbers...

Then how old are you?
40 years ago I was a kid 2 years old...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

FELIX

  • Bull Frog
  • Posts: 241
Re: Converter binary double to decimal.
« Reply #5 on: February 06, 2019, 12:34:26 PM »
For more than 40 years I have not worked with binary numbers...

Then how old are you?
40 years ago I was a kid 2 years old...

My age is: 00111101
OK.

Rod

  • Newt
  • Posts: 185
Re: Converter binary double to decimal.
« Reply #6 on: February 06, 2019, 04:10:16 PM »
You're welcome. I didn't even remember that I was taught this once. It was bugging my though and I couldn't resist working on it.

Excellent ROD, now it's easy to convert the coordinates that are in binary.
For more than 40 years I have not worked with binary numbers but it's like cycling, we lose practice but not balance.
"All models are wrong, some models are useful" - George Box