Skip to content

Instantly share code, notes, and snippets.

@briankung
Created June 29, 2019 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briankung/09018003189e8b2515441494c8462029 to your computer and use it in GitHub Desktop.
Save briankung/09018003189e8b2515441494c8462029 to your computer and use it in GitHub Desktop.
binary to float converter
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