Black
Black

Reputation: 101

Convert hexadecimal to decimal number

Is there a function in Lua which allows to convert a hex number to a decimal number?

Upvotes: 8

Views: 31548

Answers (1)

lhf
lhf

Reputation: 72352

Use tonumber to convert from strings to numbers.

Both these print 2014:

print(tonumber("0x7DE"))

print(tonumber("7DE",16))

You can also use hexadecimal constants directly:

print(0x7DE)

Upvotes: 22

Related Questions