Bitwise Operations

bitand

Syntax

bitand(x,y)
bitand(x,y,assumedType)

Description

Performs the logical AND operation on each pair of corresponding bits of x and y. If x or y is an array, then it will perform the logical AND operation of each pair of elements.

  • The function expects that the length of all input arrays to be equal. It will expand any scalar inputs to the appropriately sized array before performing bitand of each element.
  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before computing the logical AND operation.
  • If assumedType is provided, it identifies the type for the inputs x and y as either fixed width signed or fixed width unsigned integers. It must have the form 'intN' or 'uintN' where N is a positive integer.

bitcmp

Syntax

bitcmp(x)
bitcmp(x,assumedType)

Description

Performs the bitwise complement of the operand. The input may be singular or an array of numerical or logical values. If x is an array, it computes bitcmp for each element in x.

  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before computing the complement.
  • If assumedType is provided, it identifies the type for the input x as either a fixed width signed or fixed width unsigned integer. It must have the form 'intN' or 'uintN' where N is a positive integer.

bitor

Syntax

bitor(x,y)
bitor(x,y,assumedType)

Description

Performs the logical OR operation on each pair of corresponding bits of x and y. If x or y is an array, then it will perform the logical OR operation of each pair of elements.

  • The function expects that the length of all input arrays to be equal. It will expand any scalar inputs to the appropriately sized array before performing bitor of each element.
  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before computing the logical OR operation.
  • If assumedType is provided, it identifies the type for the inputs x and y as either fixed width signed or fixed width unsigned integers. It must have the form 'intN' or 'uintN' where N is a positive integer.

bitget

Syntax

bitget(x,bitPosition)
bitget(x,bitPosition,assumedType)

Description

Returns the bit value of x at location bitPosition. The bitPosition must be a positive integer between 1 and the number of bits in the integer class of x. The bitPosition may be an integer array, in which case, this function returns the bit values of x and each location identified in the array bitPosition.

  • If x is an array, it returns the bit value at position bitPosition for each element in x. If bitPosition is an array, its length must agree with the length of x.
  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before retrieving any bit values.
  • If assumedType is provided, it identifies the type for the input x as either a fixed width signed or fixed width unsigned integer. It must have the form 'intN' or 'uintN' where N is a positive integer.

bitset

Syntax

bitset(x,bitPosition,val)
bitset(x,bitPosition,val,assumedType)

Description

Returns x with the bit at location bitPosition set to val. If x is an array, it returns an array where each element of x has the bitPosition set to val. The bitPosition must be a positive integer between 1 and the number of bits in the integer class of x.

  • The operand bitPosition may also be an integer array. Note that val may be a scalar or numeric array, however, val will be converted to logical array before it is used to set bits in x.
  • The function expects that the length of all input arrays to be equal. It will expand any scalar inputs to the appropriately sized array before performing bitset of each element.
  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before setting any bits.
  • If assumedType is provided, it identifies the type for the input x as either a fixed width signed or fixed width unsigned integer. It must have the form 'intN' or 'uintN' where N is a positive integer.

bitshift

Syntax

bitshift(x,n)
bitshift(x,n,assumedType)

Description

When n is positive integer, return x shifted to the left by n bits. This is equivalent to multiplying x by 2^n. When n is negative, return x shifted to the right by n bits. This is equivalent to dividing by 2^n and rounding to the nearest integer less than or equal to the result. Any overflow bits are truncated.

  • When x is real, Grackle will convert the operand to an unsigned 64bit integer before performing the shift operation. Negative real values for x are not permitted.
  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before shifting any bits.
  • If assumedType is provided, it identifies the type for the input x as either a fixed width signed or fixed width unsigned integer. It must have the form 'intN' or 'uintN' where N is a positive integer.

bitxor

Syntax

bitxor(x,y)
bitxor(x,y,assumedType)

Description

Performs the logical exclusive OR operation on each pair of corresponding bits of the operands. If x or y is an array, then it will perform the logical XOR operation of each pair of elements.

  • The function expects that the length of all input arrays to be equal. It will expand any scalar inputs to the appropriately sized array before performing bitxor of each element.
  • If assumedType is not provided, Grackle will implicitly convert real inputs to 64bit unsigned integers before computing the logical XOR operation.
  • If assumedType is provided, it identifies the type for the inputs x and y as either fixed width signed or fixed width unsigned integers. It must have the form 'intN' or 'uintN' where N is a positive integer.