Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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