[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to get the 2-complenent of a negative number in Lua 5.2?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 4 Jul 2016 09:47:29 -0300
> On 7/4/16, Martin <eden_martin_fuhrspam@gmx.de> wrote:
> >> unfortunately, in Lua 5.2 it fails:
> >>
> >> -- Lua 5.2
> >> > print(("%x"):format(-123456))
> >> stdin:1: bad argument #1 to 'format' (not a non-negative number in
> >> proper range)
> >>
> >> Is there a solution that works in 5.2 as well?
> >>
> > print(('%x'):format(bit32.band(-2)))
>
> Works perfectly! Thanks.
Another option:
print(('%x'):format(-2 % 2^32))
-- Roberto