Skip to content

Instantly share code, notes, and snippets.

@3en
Created August 6, 2011 14:31
Show Gist options
  • Save 3en/1129386 to your computer and use it in GitHub Desktop.
Save 3en/1129386 to your computer and use it in GitHub Desktop.
Convert array of hex decimal representation (ObjectId.data) to a hex string
# Converts an array of hex decimal representation (ObjectId.data) to a hex string.
# e.g [78, 26, 131, 172, 159, 165, 6, 0, 1, 0, 0, 125] > '4e1a83ac9fa506000100007d'
# convert_to_hex_string([78, 26, 131, 172, 159, 165, 6, 0, 1, 0, 0, 125])
def convert_to_hex_string(dec_array)
dec_array.map { |n| "%02x" % n }.join
end
@hmarr
Copy link

hmarr commented Aug 7, 2011

def convert_to_hex_string(dec_array)
  dec_array.map { |n| "%02x" % n }.join
end

@3en
Copy link
Author

3en commented Aug 7, 2011

Nice. So much neater :-)

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