Created
November 5, 2017 12:45
-
-
Save exts/f9b0654776f48275d52fcf838725e9cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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