I am wondering how to convert a 64 bit binary string to a double float in ruby. The string that I have is as follows:
binaryString = "0011111111110000000000000000000000000000000000000000000000000000"
Using an online converter (http://www.binaryconvert.com/convert_double.html?) I know that the value should be 1.0. However, I'm attempting to use the ruby unpack to convert to double, and I'm not getting the correct result.
double_value = binaryString.unpack("G")
Gives me double_value = 1.3983819593719592e-76
I've tried other directives like "F" and "D", but none yield correct results.
Any ideas what I am doing wrong? Thank you for the help!
binaryStringis a string, so you need quotation marks on the right. (As written,binaryStringis an integer whose digits are all zeros and ones, and whose two leading zeroes are of no significance) If it is meant to be a string, why not use it's integer value,binaryString.to_i(2) # => 4607182418800017408? You need to edit the question to correct or clarify.