Useing tonumber() to convert to binary, hex, ect

Hey, I am working on a simple app to convert between decimal, binary, and hex. The tonumber() function makes it super easy to convert from binary/hex to decimal, but I cant find any documentation on how to use it to convert from decimal to binary/hex.

Is this possible? Thanks in advance!

You’re really talking about converting it to a string you can print or do something else with.

https://docs.coronalabs.com/api/library/string/format.html

local converted = string.format( "0X%8.8X", 100 ) print( converted ) local converted = string.format( "0X%8.8X", 3735928559 ) print( converted )

prints:

0X00000064 0XDEADBEEF

Ah, thank you!

After further research I found that converting to binary does not have a function so I made my own, but this helped convert to octal and hex.

Thanks for the help!

You’re really talking about converting it to a string you can print or do something else with.

https://docs.coronalabs.com/api/library/string/format.html

local converted = string.format( "0X%8.8X", 100 ) print( converted ) local converted = string.format( "0X%8.8X", 3735928559 ) print( converted )

prints:

0X00000064 0XDEADBEEF

Ah, thank you!

After further research I found that converting to binary does not have a function so I made my own, but this helped convert to octal and hex.

Thanks for the help!