Skip to content

Instantly share code, notes, and snippets.

@nmarley
Last active July 2, 2019 12:56
Show Gist options
  • Save nmarley/33ef02f2a674d5ac1dac to your computer and use it in GitHub Desktop.
Save nmarley/33ef02f2a674d5ac1dac to your computer and use it in GitHub Desktop.
Ruby reverse bytes in hex string (endianness)
# Ruby reverse bytes in hex string (endianness)
def flip_bytes(hex)
return hex.scan(/../).reverse.join('')
end
hs = "e0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7"
puts flip_bytes(hs)
# => "c762a6567f3cc092f0684bb62b7e00a84890b990f07cc71a6bb58d64b98e02e0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment