Guest User

Untitled

a guest
Apr 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. --This is 2 simple function to transform some number (under 255) to hexadecimal number and in the other way.
  2. --This is made for PICO-8
  3.  
  4. function dec_to_hexa(dec)
  5. local hex="0123456789abcdef"
  6. local sortie=""
  7. sortie=sortie..sub(hex,flr(dec%16)+1,flr(dec%16)+1)
  8. dec=flr((dec/16))
  9. sortie=sub(hex,(dec%16)+1,(dec%16)+1)..sortie
  10. return sortie
  11. end
  12.  
  13. function hexa_to_dec(hexa)
  14. local hex="0123456789abcdef"
  15. local sortie=0
  16.  
  17. for i=-2,-1 do
  18. for l=1,16 do
  19. if sub(hex,l,l)==sub(hexa,i,i) then
  20. sortie=16^(abs(i)-1)*(l-1)+sortie
  21. end
  22. end
  23. end
  24.  
  25. return sortie
  26. end
  27.  
  28. entree=25
  29.  
  30. print(dec_to_hexa(entree))
  31. print(hexa_to_dec(dec_to_hexa(entree)))
Add Comment
Please, Sign In to add comment