binary

Bitwise binary logical operations on 32-bit words.

Summary
binaryBitwise binary logical operations on 32-bit words.
Functions
and32Bitwise logical “and” of two 32-bit words.
and64Bitwise logical “and” of two 64-bit words.
andBytesBitwise logical “and” of two Bytes buffers.
extract32Extract a range of bits from a 32-bit word.
extract64Extract a range of bits from a 64-bit word.
get32Get a specific bit from a 32-bit word.
get64Get a specific bit from a 64-bit word.
not32Invert all bits in a 32-bit word.
not64Invert all bits in a 64-bit word.
notBytesInvert all bits in a Bytes buffer.
or32Bitwise logical “or” of two 32-bit words.
or64Bitwise logical “or” of two 64-bit words.
orBytesBitwise logical “or” of two Bytes buffers.
replace32Replace a range of bits in a 32-bit word.
replace64Replace a range of bits in a 64-bit word.
set32Set a specific bit in a 32-bit word.
set64Set a specific bit in a 64-bit word.
shiftLeft32Shift a 32-bit word left by a given number of bits.
shiftLeft64Shift a 64-bit word left by a given number of bits.
shiftRight32Shift a 32-bit word right by a given number of bits.
shiftRight64Shift a 64-bit word right by a given number of bits.
shiftRightSigned32Shift a 32-bit word right by a given number of bits, preserving the sign bit.
shiftRightSigned64Shift a 64-bit word right by a given number of bits, preserving the sign bit.
xor32Bitwise logical “exclusive-or” of two 32-bit words.
xor64Bitwise logical “exclusive-or” of two 64-bit words.
xorBytesBitwise logical “exclusive-or” of two Bytes buffers.

Functions

and32

DECLARE NATIVE FUNCTION and32( x,
y: Number): Number

Bitwise logical “and” of two 32-bit words.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 0 |
---+---+---+
 1 | 0 | 1 |
---+---+---+
 ^
 y

and64

DECLARE NATIVE FUNCTION and64( x,
y: Number): Number

Bitwise logical “and” of two 64-bit words.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 0 |
---+---+---+
 1 | 0 | 1 |
---+---+---+
 ^
 y

andBytes

DECLARE NATIVE FUNCTION andBytes( x,
y: Bytes): Bytes

Bitwise logical “and” of two Bytes buffers.  The size of both input parameters must be the same.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 0 |
---+---+---+
 1 | 0 | 1 |
---+---+---+
 ^
 y

extract32

DECLARE NATIVE FUNCTION extract32( x,
 n,
w: Number): Number

Extract a range of bits from a 32-bit word.

Parameters

xnumber to extract bits from
nbit position of the lowest order bit to extract
wwidth of bit range to extract

Description

This function extracts a given range of bits.  The bits in an word are numbered starting at 0 for the least significant bit.

The function call

binary.extract(x, 5, 3)

will extract the following bits from the word

31    28      24      20      16      12       8       4       0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                                |     |
                                                +-----+

extract64

DECLARE NATIVE FUNCTION extract64( x,
 n,
w: Number): Number

Extract a range of bits from a 64-bit word.

Parameters

xnumber to extract bits from
nbit position of the lowest order bit to extract
wwidth of bit range to extract

Description

This function extracts a given range of bits.  The bits in an word are numbered starting at 0 for the least significant bit.

The function call

binary.extract(x, 5, 3)

will extract the following bits from the word

31    28      24      20      16      12       8       4       0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                                |     |
                                                +-----+

get32

DECLARE NATIVE FUNCTION get32( x,
n: Number): Boolean

Get a specific bit from a 32-bit word.

Parameters

xnumber to extract the bit from
nbit position of the bit to extract

Description

This function returns a Boolean value indicting whether the indicated bit is set (TRUE) or not (FALSE).

get64

DECLARE NATIVE FUNCTION get64( x,
n: Number): Boolean

Get a specific bit from a 64-bit word.

Parameters

xnumber to extract the bit from
nbit position of the bit to extract

Description

This function returns a Boolean value indicting whether the indicated bit is set (TRUE) or not (FALSE).

not32

DECLARE NATIVE FUNCTION not32(x: Number): Number

Invert all bits in a 32-bit word.

not64

DECLARE NATIVE FUNCTION not64(x: Number): Number

Invert all bits in a 64-bit word.

notBytes

DECLARE NATIVE FUNCTION notBytes(x: Bytes): Bytes

Invert all bits in a Bytes buffer.

or32

DECLARE NATIVE FUNCTION or32( x,
y: Number): Number

Bitwise logical “or” of two 32-bit words.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 1 |
---+---+---+
 1 | 1 | 1 |
---+---+---+
 ^
 y

or64

DECLARE NATIVE FUNCTION or64( x,
y: Number): Number

Bitwise logical “or” of two 64-bit words.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 1 |
---+---+---+
 1 | 1 | 1 |
---+---+---+
 ^
 y

orBytes

DECLARE NATIVE FUNCTION orBytes( x,
y: Bytes): Bytes

Bitwise logical “or” of two Bytes buffers.  The size of both input parameters must be the same.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 1 |
---+---+---+
 1 | 1 | 1 |
---+---+---+
 ^
 y

replace32

DECLARE NATIVE FUNCTION replace32( x,
 n,
 w,
y: Number): Number

Replace a range of bits in a 32-bit word.

Parameters

xnumber to replace bits into
nbit position of the lowest order bit to replace
wwidth of bit range to replace
ynew bits to replace

Description

This function replaces a given range of bits with new bits.  The bits in an word are numbered starting at 0 for the least significant bit.

The function call

binary.replace(x, 5, 3, 7)

will replace the following bits in the word

31    28      24      20      16      12       8       4       0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                                |     |
                                                +-----+

Each of the bits numbered 5, 6, and 7 would be set to 1 (from the input value 7).

replace64

DECLARE NATIVE FUNCTION replace64( x,
 n,
 w,
y: Number): Number

Replace a range of bits in a 64-bit word.

Parameters

xnumber to replace bits into
nbit position of the lowest order bit to replace
wwidth of bit range to replace
ynew bits to replace

Description

This function replaces a given range of bits with new bits.  The bits in an word are numbered starting at 0 for the least significant bit.

The function call

binary.replace(x, 5, 3, 7)

will replace the following bits in the word

31    28      24      20      16      12       8       4       0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                                |     |
                                                +-----+

Each of the bits numbered 5, 6, and 7 would be set to 1 (from the input value 7).

set32

DECLARE NATIVE FUNCTION set32( x,
n: Number,
v: Boolean): Number

Set a specific bit in a 32-bit word.

Parameters

xnumber to set the bit
nbit position of the bit to set
vbit value to set, 0 (FALSE) or 1 (TRUE)

Description

This function returns a new value with the given bit set according to the parameter v.

set64

DECLARE NATIVE FUNCTION set64( x,
n: Number,
v: Boolean): Number

Set a specific bit in a 64-bit word.

Parameters

xnumber to set the bit
nbit position of the bit to set
vbit value to set, 0 (FALSE) or 1 (TRUE)

Description

This function returns a new value with the given bit set according to the parameter v.

shiftLeft32

DECLARE NATIVE FUNCTION shiftLeft32( x,
n: Number): Number

Shift a 32-bit word left by a given number of bits.

Parameters

xword to shift
nnumber of bits to shift left

Description

New bits shifted into the right hand side of the word are 0.

shiftLeft64

DECLARE NATIVE FUNCTION shiftLeft64( x,
n: Number): Number

Shift a 64-bit word left by a given number of bits.

Parameters

xword to shift
nnumber of bits to shift left

Description

New bits shifted into the right hand side of the word are 0.

shiftRight32

DECLARE NATIVE FUNCTION shiftRight32( x,
n: Number): Number

Shift a 32-bit word right by a given number of bits.

Parameters

xword to shift
nnumber of bits to shift right

Description

New bits shifted into the left hand side of the word are 0.

shiftRight64

DECLARE NATIVE FUNCTION shiftRight64( x,
n: Number): Number

Shift a 64-bit word right by a given number of bits.

Parameters

xword to shift
nnumber of bits to shift right

Description

New bits shifted into the left hand side of the word are 0.

shiftRightSigned32

DECLARE NATIVE FUNCTION shiftRightSigned32( x,
n: Number): Number

Shift a 32-bit word right by a given number of bits, preserving the sign bit.

Parameters

xword to shift
nnumber of bits to shift right

Description

New bits shifted into the left hand side of the word are the same as the original leftmost bit.

shiftRightSigned64

DECLARE NATIVE FUNCTION shiftRightSigned64( x,
n: Number): Number

Shift a 64-bit word right by a given number of bits, preserving the sign bit.

Parameters

xword to shift
nnumber of bits to shift right

Description

New bits shifted into the left hand side of the word are the same as the original leftmost bit.

xor32

DECLARE NATIVE FUNCTION xor32( x,
y: Number): Number

Bitwise logical “exclusive-or” of two 32-bit words.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 1 |
---+---+---+
 1 | 1 | 0 |
---+---+---+
 ^
 y

xor64

DECLARE NATIVE FUNCTION xor64( x,
y: Number): Number

Bitwise logical “exclusive-or” of two 64-bit words.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 1 |
---+---+---+
 1 | 1 | 0 |
---+---+---+
 ^
 y

xorBytes

DECLARE NATIVE FUNCTION xorBytes( x,
y: Bytes): Bytes

Bitwise logical “exclusive-or” of two Bytes buffers.  The size of both input parameters must be the same.

For each bit in the inputs, the following truth table determines the output bit:

   | 0 | 1 | <- x
---+---+---+
 0 | 0 | 1 |
---+---+---+
 1 | 1 | 0 |
---+---+---+
 ^
 y
DECLARE NATIVE FUNCTION and32( x,
y: Number): Number
Bitwise logical “and” of two 32-bit words.
DECLARE NATIVE FUNCTION and64( x,
y: Number): Number
Bitwise logical “and” of two 64-bit words.
DECLARE NATIVE FUNCTION andBytes( x,
y: Bytes): Bytes
Bitwise logical “and” of two Bytes buffers.
DECLARE NATIVE FUNCTION extract32( x,
 n,
w: Number): Number
Extract a range of bits from a 32-bit word.
DECLARE NATIVE FUNCTION extract64( x,
 n,
w: Number): Number
Extract a range of bits from a 64-bit word.
DECLARE NATIVE FUNCTION get32( x,
n: Number): Boolean
Get a specific bit from a 32-bit word.
DECLARE NATIVE FUNCTION get64( x,
n: Number): Boolean
Get a specific bit from a 64-bit word.
DECLARE NATIVE FUNCTION not32(x: Number): Number
Invert all bits in a 32-bit word.
DECLARE NATIVE FUNCTION not64(x: Number): Number
Invert all bits in a 64-bit word.
DECLARE NATIVE FUNCTION notBytes(x: Bytes): Bytes
Invert all bits in a Bytes buffer.
DECLARE NATIVE FUNCTION or32( x,
y: Number): Number
Bitwise logical “or” of two 32-bit words.
DECLARE NATIVE FUNCTION or64( x,
y: Number): Number
Bitwise logical “or” of two 64-bit words.
DECLARE NATIVE FUNCTION orBytes( x,
y: Bytes): Bytes
Bitwise logical “or” of two Bytes buffers.
DECLARE NATIVE FUNCTION replace32( x,
 n,
 w,
y: Number): Number
Replace a range of bits in a 32-bit word.
DECLARE NATIVE FUNCTION replace64( x,
 n,
 w,
y: Number): Number
Replace a range of bits in a 64-bit word.
DECLARE NATIVE FUNCTION set32( x,
n: Number,
v: Boolean): Number
Set a specific bit in a 32-bit word.
DECLARE NATIVE FUNCTION set64( x,
n: Number,
v: Boolean): Number
Set a specific bit in a 64-bit word.
DECLARE NATIVE FUNCTION shiftLeft32( x,
n: Number): Number
Shift a 32-bit word left by a given number of bits.
DECLARE NATIVE FUNCTION shiftLeft64( x,
n: Number): Number
Shift a 64-bit word left by a given number of bits.
DECLARE NATIVE FUNCTION shiftRight32( x,
n: Number): Number
Shift a 32-bit word right by a given number of bits.
DECLARE NATIVE FUNCTION shiftRight64( x,
n: Number): Number
Shift a 64-bit word right by a given number of bits.
DECLARE NATIVE FUNCTION shiftRightSigned32( x,
n: Number): Number
Shift a 32-bit word right by a given number of bits, preserving the sign bit.
DECLARE NATIVE FUNCTION shiftRightSigned64( x,
n: Number): Number
Shift a 64-bit word right by a given number of bits, preserving the sign bit.
DECLARE NATIVE FUNCTION xor32( x,
y: Number): Number
Bitwise logical “exclusive-or” of two 32-bit words.
DECLARE NATIVE FUNCTION xor64( x,
y: Number): Number
Bitwise logical “exclusive-or” of two 64-bit words.
DECLARE NATIVE FUNCTION xorBytes( x,
y: Bytes): Bytes
Bitwise logical “exclusive-or” of two Bytes buffers.
Close