Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
/ lua-bit64 Public archive
forked from tst2005/lua-bit64

Lua bitwise operators on 64-bit integers

License

Notifications You must be signed in to change notification settings

ManuelBlanc/lua-bit64

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lua-bit64

LuaJIT library for bitwise operations on 64-bit integers.

NOTE The bit libray in LuaJIT 2.1.0-beta3 supports 64-bit types (and JIT compiles them too!). This library is for older versions of LuaJIT.

API

The call semantics are the same as in the Lua BitOp extension module.

a, b = bit64.split(x) -- Splits a 64-bit number to its hi/lo 32-bit components.
y = bit64.join(a, b) -- Concatenates two Lua numbers into a 64-bit one.
a = bit64.hi(x) -- Returns the hi 32-bits.
b = bit64.lo(x) -- Returns the lo 32-bits.
y = bit64.band(x1 [,x2...]) -- Bitwise AND of all its arguments.
y = bit64.bor(x1 [,x2...]) -- Same for bitwise OR.
y = bit64.bxor(x1 [,x2...]) -- Same for bitwise XOR.
y = bit64.bnot(x) -- Bitwise NOT of its argument.
y = bit64.lshift(x, n) -- Bitwise logical left-shift by n bits.
y = bit64.rshift(x, n) -- Same for bitwise logical right-shift.
y = bit64.arshift(x, n) -- Same for bitwise arithmetic right-shift.
y = bit64.rol(x, n) -- Bitwise left rotation by n bits.
y = bit64.ror(x, n) -- Same for bitwise right rotation.
y = bit64.bswap(x) -- Swaps the bytes of its argument and returns it.
y = bit64.tohex(x [,n]) -- Converts 1st arg to a hex string. 2nd arg is length.

Types:

  • a, b and n are Lua numbers.
  • y is a 64-bit unsigned integer.
  • x can be a Lua number or a 64-bit integer (signed or unsigned).

Modifying & testing

The repository includes a C program that generates a test suite for the module. To run the tests make sure you have a C compiler and execute:

make test

License

MIT Licensed. See the LICENSE file.

About

Lua bitwise operators on 64-bit integers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 60.8%
  • C 36.0%
  • Makefile 3.2%