BitAnd

Boolean Math Functions


Boolean operations work with the invidual bits in the binary composition of a number. The Lua core language does not include built-in functions for doing Boolean math, so they are included in the Pro Script module.

The Boolean operations always take numbers as arguments. However, strings showing the bit patterns ate often useful or convenient. Bit strings can show either hexadecimal or binary representations of numbers, but the strings must be converted to decimal numbers to be used by Boolean functions like BitAnd or BitTest. The hexadecimal and binary representations have the least significant bit at the right end of the string.

To aid in converting between decimal numbers and hexadecimal or binary strings, 6 conversion functions are provided. For example, the number 46 can be converted to the string "2E" (hexadecimal) or "101110" (binary), and vice versa. Hexadecimal and binary strings are returned at full length, which means 32 characters for the binary representation of a 32-bit number or 8 characters for the hexadecimal representation of a 32-bit number. To reduce the string length, you can use the BitTrim function to strip all leading 0's from the hexadecimal or binary string. Conversions from binary or hexadecimal strings to decimal form do not care whether the leading 0's are present.

Boolean Operations

BitAnd

Performs the bit-wise AND between two numbers.

BitOr

Performs the bit-wise OR between two numbers.

BitXor

Performs the bit-wise XOR between two numbers.

BitNot

Performs the bit-wise NOT, or complement of a number.

BitNand

Performs the bit-wise NAND between two numbers.

BitNor

Performs the bit-wise NOR between two numbers.

BitTest

Tests if the bit in a given position is a 1 or 0.

Conversions

BitDtoX

Converts a decimal number to a hexadecimal string.

BitXtoD

Converts a hexadecimal string to a decimal number.

BitXtoB

Converts a hexadecimal string to a binary string.

BitBtoX

Converts a binary string to a hexadecimal string.

BitDtoB

Converts a decimal number to a binary string.

BitBtoD

Converts a binary string to a decimal number.

BitTrim

Trims leading 0's from a hexadecimal or binary string.

Related Topics

Contents