mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 14:11:29 +00:00
67 lines
2.3 KiB
Plaintext
67 lines
2.3 KiB
Plaintext
---
|
|
-- Bitwise operations on integers.
|
|
--
|
|
-- Lua does not provide bitwise logical operations. Since they are often useful
|
|
-- for low-level network communication, Reuben Thomas' BitLib
|
|
-- (http://luaforge.net/projects/bitlib) for Lua has been integrated into NSE.
|
|
-- The arguments to the bitwise operation functions should be integers. The
|
|
-- number of bits available for logical operations depends on the data type used
|
|
-- to represent Lua numbers. This is typically 8-byte IEEE floats (double),
|
|
-- which give 53 bits (the size of the mantissa).
|
|
--
|
|
-- This implies that the bitwise operations won't work (as expected) for numbers
|
|
-- larger than 10^14. You can use them with 32-bit wide numbers without any
|
|
-- problems. Operations involving 64-bit wide numbers, however, may not return
|
|
-- the expected result.
|
|
--
|
|
-- The logical operations start with "b" to avoid
|
|
-- clashing with reserved words; although <code>xor</code> isn't a
|
|
-- reserved word, it seemed better to use <code>bxor</code> for
|
|
-- consistency.
|
|
--
|
|
-- @author Reuben Thomas
|
|
-- @copyright BSD License
|
|
|
|
module "bit"
|
|
|
|
--- Returns the one's complement of <code>a</code>.
|
|
-- @param a Number.
|
|
-- @return The one's complement of <code>a</code>.
|
|
function bnot(a)
|
|
|
|
--- Returns the bitwise and of all its arguments.
|
|
-- @param ... A variable number of Numbers to and.
|
|
-- @return The anded result.
|
|
function band(...)
|
|
|
|
--- Returns the bitwise or of all its arguments.
|
|
-- @param ... A variable number of Numbers to or.
|
|
-- @return The ored result.
|
|
function bor(...)
|
|
|
|
--- Returns the bitwise exclusive or of all its arguments.
|
|
-- @param ... A variable number of Numbers to exclusive or.
|
|
-- @return The exclusive ored result.
|
|
function bxor(...)
|
|
|
|
--- Returns <code>a</code> left-shifted by <code>b</code> places.
|
|
-- @param a Number to perform the shift on.
|
|
-- @param b Number of shifts.
|
|
function lshift(a, b)
|
|
|
|
--- Returns <code>a</code> right-shifted by <code>b</code> places.
|
|
-- @param a Number to perform the shift on.
|
|
-- @param b Number of shifts.
|
|
function rshift(a, b)
|
|
|
|
--- Returns <code>a</code> arithmetically right-shifted by <code>b</code>
|
|
-- places.
|
|
-- @param a Number to perform the shift on.
|
|
-- @param b Number of shifts.
|
|
function arshift(a, b)
|
|
|
|
--- Returns the integer remainder of <code>a</code> divided by <code>b</code>.
|
|
-- @param a Dividend.
|
|
-- @param b Divisor.
|
|
function mod(a, b)
|