Skip to content

Instantly share code, notes, and snippets.

@tastycode
Forked from Nurdok/python_conversion.md
Last active December 16, 2015 11:39
Show Gist options
  • Save tastycode/5428642 to your computer and use it in GitHub Desktop.
Save tastycode/5428642 to your computer and use it in GitHub Desktop.

Ruby/Python Number Conversion Chart

From To Python Ruby
45 "45" str(data) data.to_s
45 "101101" bin(data) data.to_s(2)
45 "2D" hex(data) data.to_s(16)
45 "\x00\x00\x00\x2d" struct.pack('!i', data) ?
"45" 45 int(data) data.to_i
"45" "3435" data.encode('hex') ?
"101101" 45 int(data, 2) data.to_i(2)
"2D" 45 data.to_i(16)
"2D" "\x2d" binascii.unhexlify(data) or data.decode('hex') ?
"\x00\x00\x00\x2d" 45 struct.unpack('!i', data)[0] ?
"\x2d" "2D" binascii.hexlify(data) ?
"3435" "45" data.decode('hex') ?

Comments are welcome here or in my original blog post regarding this table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment