Oihana PHP Arango

bit

Table of Contents

Functions

bitAnd()  : string
Return the bitwise AND of its operands.
bitConstruct()  : string
Construct a number with its bits set at the positions given in an array (zero-based).
bitDeconstruct()  : string
Deconstruct a number into the array of its set bit positions (zero-based).
bitFromString()  : string
Parse a bitstring (e.g. `"0101"`) into its numeric value.
bitNegate()  : string
Return the bitwise negation of a number, keeping up to `bits` bits.
bitOr()  : string
Return the bitwise OR of its operands.
bitPopcount()  : string
Return the number of bits set to 1 in a number (population count).
bitShiftLeft()  : string
Bitwise-shift the bits of a number to the left, keeping up to `bits` bits.
bitShiftRight()  : string
Bitwise-shift the bits of a number to the right, keeping up to `bits` bits.
bitTest()  : string
Test whether the bit at the given (zero-based) position is set in a number.
bitToString()  : string
Return the bitstring representation of a number, padded to `bits` characters.
bitXor()  : string
Return the bitwise XOR (exclusive or) of its operands.

Functions

bitAnd()

Return the bitwise AND of its operands.

bitAnd(string|int|array<string|int, mixed> $values[, string|int|null $value2 = null ]) : string

Wraps the ArangoDB AQL function BIT_AND(), which has two forms:

  • an array of numbers: BIT_AND(numbersArray),
  • two number operands: BIT_AND(value1, value2) (pass $value2).

PHP arrays are emitted as JSON literals; strings are passed through as raw AQL expressions.

Example AQL usage:

BIT_AND([1, 4, 8, 16])   // returns 0
BIT_AND(127, 255)        // returns 127
Parameters
$values : string|int|array<string|int, mixed>

The numbers array, or the first operand when $value2 is given.

$value2 : string|int|null = null

The second operand (selects the two-number form).

Tags
example
use function oihana\arango\db\functions\bit\bitAnd;

$expr = bitAnd([1, 4, 8, 16]);   // 'BIT_AND([1,4,8,16])'
$expr = bitAnd(127, 255);        // 'BIT_AND(127,255)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_and
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitConstruct()

Construct a number with its bits set at the positions given in an array (zero-based).

bitConstruct(string|array<string|int, mixed> $positions) : string

Wraps the ArangoDB AQL function BIT_CONSTRUCT(positionsArray). It is the inverse of bitDeconstruct(). A PHP array is emitted as a JSON literal; a string is passed through as a raw AQL expression.

Example AQL usage:

BIT_CONSTRUCT([1, 2, 3])   // returns 14
Parameters
$positions : string|array<string|int, mixed>

The bit positions to set (array literal or AQL expression).

Tags
example
use function oihana\arango\db\functions\bit\bitConstruct;

$expr = bitConstruct([1, 2, 3]);   // 'BIT_CONSTRUCT([1,2,3])'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_construct
bitDeconstruct()
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitDeconstruct()

Deconstruct a number into the array of its set bit positions (zero-based).

bitDeconstruct(string|int $value) : string

Wraps the ArangoDB AQL function BIT_DECONSTRUCT(value). It is the inverse of bitConstruct().

Example AQL usage:

BIT_DECONSTRUCT(14)   // returns [1, 2, 3]
Parameters
$value : string|int

The number to deconstruct.

Tags
example
use function oihana\arango\db\functions\bit\bitDeconstruct;

$expr = bitDeconstruct(14);   // 'BIT_DECONSTRUCT(14)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_deconstruct
bitConstruct()
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitFromString()

Parse a bitstring (e.g. `"0101"`) into its numeric value.

bitFromString(string $bitstring) : string

Wraps the ArangoDB AQL function BIT_FROM_STRING(bitstring). It is the inverse of bitToString(). The bitstring is emitted as a quoted string literal (json_encode), so a literal such as '0101' produces valid AQL.

Example AQL usage:

BIT_FROM_STRING("0101")   // returns 5
Parameters
$bitstring : string

The bitstring to parse (emitted as a quoted string literal).

Tags
example
use function oihana\arango\db\functions\bit\bitFromString;

$expr = bitFromString('0101');   // 'BIT_FROM_STRING("0101")'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_from_string
bitToString()
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitNegate()

Return the bitwise negation of a number, keeping up to `bits` bits.

bitNegate(string|int $value, string|int $bits) : string

Wraps the ArangoDB AQL function BIT_NEGATE(value, bits).

Example AQL usage:

BIT_NEGATE(0, 8)     // returns 255
BIT_NEGATE(255, 8)   // returns 0
Parameters
$value : string|int

The number to negate.

$bits : string|int

The number of bits to keep (0 … 32).

Tags
example
use function oihana\arango\db\functions\bit\bitNegate;

$expr = bitNegate(0, 8);   // 'BIT_NEGATE(0,8)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_negate
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitOr()

Return the bitwise OR of its operands.

bitOr(string|int|array<string|int, mixed> $values[, string|int|null $value2 = null ]) : string

Wraps the ArangoDB AQL function BIT_OR(), which has two forms:

  • an array of numbers: BIT_OR(numbersArray),
  • two number operands: BIT_OR(value1, value2) (pass $value2).

PHP arrays are emitted as JSON literals; strings are passed through as raw AQL expressions.

Example AQL usage:

BIT_OR([1, 4, 8, 16])   // returns 29
BIT_OR(1, 2)            // returns 3
Parameters
$values : string|int|array<string|int, mixed>

The numbers array, or the first operand when $value2 is given.

$value2 : string|int|null = null

The second operand (selects the two-number form).

Tags
example
use function oihana\arango\db\functions\bit\bitOr;

$expr = bitOr([1, 4, 8, 16]);   // 'BIT_OR([1,4,8,16])'
$expr = bitOr(1, 2);            // 'BIT_OR(1,2)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_or
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitPopcount()

Return the number of bits set to 1 in a number (population count).

bitPopcount(string|int $value) : string

Wraps the ArangoDB AQL function BIT_POPCOUNT(value).

Example AQL usage:

BIT_POPCOUNT(255)   // returns 8
BIT_POPCOUNT(69)    // returns 3
Parameters
$value : string|int

The number whose set bits are counted.

Tags
example
use function oihana\arango\db\functions\bit\bitPopcount;

$expr = bitPopcount(255);   // 'BIT_POPCOUNT(255)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_popcount
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitShiftLeft()

Bitwise-shift the bits of a number to the left, keeping up to `bits` bits.

bitShiftLeft(string|int $value, string|int $shift, string|int $bits) : string

Wraps the ArangoDB AQL function BIT_SHIFT_LEFT(value, shift, bits). Bits that overflow past bits positions are discarded.

Example AQL usage:

BIT_SHIFT_LEFT(1, 4, 8)   // returns 16
Parameters
$value : string|int

The number to shift.

$shift : string|int

The number of positions to shift left.

$bits : string|int

The number of bits to keep in the result (0 … 32).

Tags
example
use function oihana\arango\db\functions\bit\bitShiftLeft;

$expr = bitShiftLeft(1, 4, 8);   // 'BIT_SHIFT_LEFT(1,4,8)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_shift_left
bitShiftRight()
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitShiftRight()

Bitwise-shift the bits of a number to the right, keeping up to `bits` bits.

bitShiftRight(string|int $value, string|int $shift, string|int $bits) : string

Wraps the ArangoDB AQL function BIT_SHIFT_RIGHT(value, shift, bits). Bits that are shifted out past position 0 are discarded.

Example AQL usage:

BIT_SHIFT_RIGHT(16, 4, 8)   // returns 1
Parameters
$value : string|int

The number to shift.

$shift : string|int

The number of positions to shift right.

$bits : string|int

The number of bits to keep in the result (0 … 32).

Tags
example
use function oihana\arango\db\functions\bit\bitShiftRight;

$expr = bitShiftRight(16, 4, 8);   // 'BIT_SHIFT_RIGHT(16,4,8)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_shift_right
bitShiftLeft()
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitTest()

Test whether the bit at the given (zero-based) position is set in a number.

bitTest(string|int $value, string|int $index) : string

Wraps the ArangoDB AQL function BIT_TEST(value, index).

Example AQL usage:

BIT_TEST(255, 0)   // returns true
BIT_TEST(0, 3)     // returns false
Parameters
$value : string|int

The number to test.

$index : string|int

The zero-based bit position to test.

Tags
example
use function oihana\arango\db\functions\bit\bitTest;

$expr = bitTest(255, 0);   // 'BIT_TEST(255,0)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_test
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitToString()

Return the bitstring representation of a number, padded to `bits` characters.

bitToString(string|int $value, string|int $bits) : string

Wraps the ArangoDB AQL function BIT_TO_STRING(value, bits). It is the inverse of bitFromString().

Example AQL usage:

BIT_TO_STRING(7, 8)   // returns "00000111"
Parameters
$value : string|int

The number to represent.

$bits : string|int

The number of bits (length of the resulting string, 0 … 32).

Tags
example
use function oihana\arango\db\functions\bit\bitToString;

$expr = bitToString(7, 8);   // 'BIT_TO_STRING(7,8)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_to_string
bitFromString()
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

bitXor()

Return the bitwise XOR (exclusive or) of its operands.

bitXor(string|int|array<string|int, mixed> $values[, string|int|null $value2 = null ]) : string

Wraps the ArangoDB AQL function BIT_XOR(), which has two forms:

  • an array of numbers: BIT_XOR(numbersArray),
  • two number operands: BIT_XOR(value1, value2) (pass $value2).

PHP arrays are emitted as JSON literals; strings are passed through as raw AQL expressions.

Example AQL usage:

BIT_XOR([1, 2, 3])   // returns 0
BIT_XOR(1, 5)        // returns 4
Parameters
$values : string|int|array<string|int, mixed>

The numbers array, or the first operand when $value2 is given.

$value2 : string|int|null = null

The second operand (selects the two-number form).

Tags
example
use function oihana\arango\db\functions\bit\bitXor;

$expr = bitXor([1, 2, 3]);   // 'BIT_XOR([1,2,3])'
$expr = bitXor(1, 5);        // 'BIT_XOR(1,5)'
see
https://docs.arangodb.com/stable/aql/functions/bit/#bit_xor
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results