bit.tonumber
Lua function

bit.tonumber

Summary

Convert a string into a number

Prototype

n = bit.tonumber (s, base)



Description

This takes a string, and converts it into a number. Unlike the standard Lua tonumber function this function will handle up to a 52-bit number (the default Lua number conversion will only go to 32-bit numbers).

eg.


print (bit.tonumber ("A7C5AC471", 16)) -->  45035996273


The base is optional and defaults to 10. The base can be in the range 2 to 36. Fractional numbers are not supported, nor are numbers with exponents (eg. 10.24e15). For such numbers use the standard Lua "tonumber" function.

Because of limitations in the size of a floating point number, the maximum string value that can be converted is a 52 bit number, ie: hex FFFFFFFFFFFFF (decimal 4503599627370495).

Leading whitespace is skipped. After that, there can be an optional + or - sign.



See Also ...

Topics

DOC_lua_base Lua base functions
DOC_lua_bc Lua bc (big number) functions
DOC_lua_bit Lua bit manipulation functions
DOC_lua_coroutines Lua coroutine functions
DOC_lua_debug Lua debug functions
DOC_lua_io Lua io functions
DOC_lua_math Lua math functions
DOC_lua_os Lua os functions
DOC_lua_package Lua package functions
DOC_lua_rex Lua PCRE regular expression functions
DOC_lua Lua script extensions
DOC_lua_string Lua string functions
DOC_lua_tables Lua table functions
DOC_lua_utils Lua utilities
DOC_scripting Scripting

Lua functions

LUA_bit.ashr bit.ashr (Shifts a number right, preserving sign)
LUA_bit.band bit.band (Bitwise 'and')
LUA_bit.bor bit.bor (Bitwise 'or')
LUA_bit.mod bit.mod (Bitwise 'modulus' (remainder after integer divide))
LUA_bit.neg bit.neg (Bitwise negate (ones complement))
LUA_bit.shl bit.shl (Shifts a number left)
LUA_bit.shr bit.shr (Shifts a number right)
LUA_bit.tostring bit.tostring (Convert a number into a string)
LUA_bit.xor bit.xor (Bitwise 'exclusive or')

(Help topic: lua=bit.tonumber)

DOC_contents Documentation contents page