Skip to content

How to convert from decimal to hex? #304

Answered by FoolMuun
FoolMuun asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a possible solution:

def hex(dec)
  if ($dec==0) 0
  else hexcalc($dec,"")

def hexcalc(dec, result)
  let hexdict = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]
  if ($dec!=0) hexcalc(floor($dec/16), $hexdict[mod($dec,16)] + $result)  
  else $result

hex(1234)

Output:
"4D2"

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@FoolMuun
Comment options

Answer selected by FoolMuun
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
support Users asking how to solve a specific issue
2 participants