Hex number constants in Lua

Posted by Nick Gammon on Mon 16 Jun 2008 01:23 AM — 1 posts, 8,735 views.

Australia Forum Administrator #0
I recently stumbled across a feature of Lua of which I was unaware, as it is not mentioned in the hard-copy Programming In Lua manual.

Lua these days allows you to use hex constants (similar to C) by prefixing them by 0x.

For example:


print (0xFF) --> 255
print (0xFFFF) --> 65535


This can be very useful where you happen to know the hex code and don't want to reach for your calculator to convert it back to decimal.