Created
June 29, 2019 19:00
-
-
Save briankung/09018003189e8b2515441494c8462029 to your computer and use it in GitHub Desktop.
binary to float converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def prettyb | |
self.chars.reverse.each_slice(4).map(&:join).join("_").reverse | |
end | |
def floatify | |
string = self.gsub('_', '') | |
if string.length % 16 != 0 | |
raise RuntimeError, "must be a single or a double precision float" | |
end | |
[string].pack('B*').unpack1('g') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment