me.369
April 4, 2018, 7:34pm
1
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
me.369
April 4, 2018, 10:35pm
3
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
me.369
April 4, 2018, 10:35pm
5
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!