[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

## Useing tonumber() to convert to binary, hex, ect Started by me.369 Apr 04 2018 11:34 AM

2 replies to this topic
tonumber

Best Answer roaminggamer , 04 April 2018 - 01:26 PM

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

```

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

### me.369

[GLOBAL: userInfoPane.html]
me.369
• Observer

• 2 posts
• Corona SDK

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!

[TOPIC: post.html]
#2

### roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
• Corona Geek

• 7,591 posts
• Corona SDK

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

```

Edited by roaminggamer, 04 April 2018 - 01:27 PM.

[TOPIC: post.html]
#3

### me.369

[GLOBAL: userInfoPane.html]
me.369
• Observer

• 2 posts
• Corona SDK

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!

[topic_controls]

[/topic_controls]