Skip to content

Instantly share code, notes, and snippets.

@exts
Created November 5, 2017 12:45
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 exts/f9b0654776f48275d52fcf838725e9cd to your computer and use it in GitHub Desktop.
Save exts/f9b0654776f48275d52fcf838725e9cd to your computer and use it in GitHub Desktop.
def to_hex(decimal)
decimal_remainder = decimal % 16
hexchars = "0123456789ABCDEF"
div = decimal / 16
if div == 0
hexchars[decimal_remainder].to_s
else
to_hex(div) + hexchars[decimal_remainder].to_s
end
end
partial_jpeg_bytes = [255, 216, 255, 224, 0, 16, 74, 70, 73, 70]
partial_jpeg_bytes.each do |b|
puts to_hex(b)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment