Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created February 14, 2015 01:24
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 cjameshuff/ba8b7851ff5c1b6eb877 to your computer and use it in GitHub Desktop.
Save cjameshuff/ba8b7851ff5c1b6eb877 to your computer and use it in GitHub Desktop.
def to_bin(bits) bits.to_s(2).rjust(64, '0') end
x = 0xFFFFFFFFFFFFFFFF
puts to_bin(x)
x = ((x & 0x00000000001FFC00) << 20) | (x & 0x00000000000003FF)
puts to_bin(x)
x = ((x & 0x000001F8000003E0) << 10) | (x & 0x00000007C000001F)
puts to_bin(x)
x = ((x & 0x00070006000C0018) << 6) | (x & 0x0000E001C0038007)
puts to_bin(x)
x = ((x & 0x0100800100020004) << 4) | (x & 0x00C06180C3018603)
puts to_bin(x)
x = ((x & 0x0080410082010402) << 2) | (x & 0x1048209041208241)
puts to_bin(x)
# 1111111111111111111111111111111111111111111111111111111111111111
# 0000000000000000000000011111111111000000000000000000001111111111
# 0000000000000111111000000000011111000000000011111000000000011111
# 0000000111000000111000011000000111000011000000111000011000000111
# 0001000011001000011000011001000011000011001000011000011001000011
# 0001001001001001001001001001001001001001001001001001001001001001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment