As the title says... Chat on...

User avatar
By Vincent Lê
#35698 Hi,

I need to convert a mac address into an integer before sending it.

On a Lua interpreter, this code is OK:
Code: Select all> mac_string = "68:a8:6d:0b:90:46"
> mac_int = tonumber(mac_string:gsub(':',''),16)
> print(string.format("%d", mac_int))
115072593268806


But On my ESP12E, this code will output:
Code: Select allmac_string="68:a8:6d:0b:90:46"
> mac_int = tonumber(mac_string:gsub(':',''),16)
> print(string.format("%d", mac_int))
2147483647


I'm guessing there is a limitation in the size of integers.

How can I perform my convertion?

Thkxs
User avatar
By devsaurus
#35699
Vincent Lê wrote:
Code: Select allmac_string="68:a8:6d:0b:90:46"
> mac_int = tonumber(mac_string:gsub(':',''),16)
> print(string.format("%d", mac_int))
2147483647

I'm guessing there is a limitation in the size of integers.

I found that the internal representation of a Lua number in C is int32 for the integer builds. This is definitely a limitation for your use case.
Have you tried the float build? Lua numbers are handled as C double there.
User avatar
By Vincent Lê
#35706 No better with the float build...
Do you know how to "truncate" my mac address in small pieces then convert them, then concatenate in a string representation of the bigint?