Bitwise operators in Corona ?

Does Corona offer any bitwise operators ?

eg.

convert a pair of numbers to binary format (high, low bytes)
concatenate them and cast to a signed short integer
[import]uid: 97524 topic_id: 18810 reply_id: 318810[/import]

Corona uses Lua as its scripting language, and Lua does not support bitwise operators natively. It will require a little extra work:

http://lua-users.org/wiki/BitwiseOperators [import]uid: 71767 topic_id: 18810 reply_id: 72410[/import]

thanks dejay

Looking at that link, will there be much difference in performance between the C Library implementation, versus the Pure Lua implementations ?

[import]uid: 97524 topic_id: 18810 reply_id: 72423[/import]

Presumably.

You don’t even have to make the choice though, because Corona doesn’t allow C extension libs.

Therefore, in Corona I would only consider using a bit op (“Pure Lua”) lib if it massively simplifies a certain problem - otherwise chances are it will simply be slower. Potential usage: Dense sets, would be interesting to see a performance comparison vs normal tables containing true for member keys.

Examples of replacing stuff that’s normally written with bit ops in C (OK, I think you know this, just for any other readers):
Concatenating two unsigned bytes n and m to an unsigned short N via normal Lua numbers:
N = n * 256 + m (would be (n << 8) | m)

Extracting them:
n = N / 256 (would be N >> 8)
m = N % 256 (would be N & 255)

Just keep the size in bits and consequently range and precision of a Corona Lua number if mind… (IIRC numbers are 64 bit doubles.) [import]uid: 58849 topic_id: 18810 reply_id: 72529[/import]