Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is 2 simple function to transform some number (under 255) to hexadecimal number and in the other way.
- --This is made for PICO-8
- function dec_to_hexa(dec)
- local hex="0123456789abcdef"
- local sortie=""
- sortie=sortie..sub(hex,flr(dec%16)+1,flr(dec%16)+1)
- dec=flr((dec/16))
- sortie=sub(hex,(dec%16)+1,(dec%16)+1)..sortie
- return sortie
- end
- function hexa_to_dec(hexa)
- local hex="0123456789abcdef"
- local sortie=0
- for i=-2,-1 do
- for l=1,16 do
- if sub(hex,l,l)==sub(hexa,i,i) then
- sortie=16^(abs(i)-1)*(l-1)+sortie
- end
- end
- end
- return sortie
- end
- entree=25
- print(dec_to_hexa(entree))
- print(hexa_to_dec(dec_to_hexa(entree)))
Add Comment
Please, Sign In to add comment