FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

BitAnd

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

BitAnd( value_1, [ value_2, ... ] )
bitand( value_1, [ value_2, ... ] )
BitAnd( value_1, [ value_2, ... ] )
BitAnd( value_1, [ value_2, ... ] )
BitAnd( value_1, [ value_2, ... ] )
BitAnd( value_1, [ value_2, ... ] )

Description

The BitAnd function returns the bit to the result if the bit exists in all numbers. The arguments must be numbers, and fractional values are truncated before the operation is applied. The result is the bitwise AND of all the arguments.

Parameters

Parameter Type Definition and Requirements

value

List of Numbers

One or more Numbers to bitwise AND.

Returns

A Number which is the bitwise AND of all supplied values.

Examples

The following query executes an array of independent bitwise AND operations and returns the answer in the result array. The result array position matches the position in the execution array.

client.query(
  [
    q.BitAnd(7),
    q.BitAnd(0, 0),
    q.BitAnd(1, 0),
    q.BitAnd(1, 1),
    q.BitAnd(7, 3),
  ]
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 7, 0, 0, 1, 3 ]
result = client.query(
  [
    q.bitand(7),
    q.bitand(0, 0),
    q.bitand(1, 0),
    q.bitand(1, 1),
    q.bitand(7, 3)
  ]
)
print(result)
[7, 0, 0, 1, 3]
result, err := client.Query(
	f.Arr{
		f.BitAnd(7),
		f.BitAnd(0, 0),
		f.BitAnd(1, 0),
		f.BitAnd(1, 1),
		f.BitAnd(7, 3),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[7 0 0 1 3]
try
{
    Value result = await client.Query(
        Arr(
            BitAnd(7),
            BitAnd(0, 0),
            BitAnd(1, 0),
            BitAnd(1, 1),
            BitAnd(7, 3)
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(LongV(7), LongV(0), LongV(0), LongV(1), LongV(3))
System.out.println(
    client.query(
        Arr(
            BitAnd(Value(7)),
            BitAnd(Value(0),Value(0)),
            BitAnd(Value(1),Value(0)),
            BitAnd(Value(1),Value(1)),
            BitAnd(Value(7),Value(3))
        )
    ).get());
[7, 0, 0, 1, 3]
[
  BitAnd(7),
  BitAnd(0, 0),
  BitAnd(1, 0),
  BitAnd(1, 1),
  BitAnd(7, 3),
]
[ 7, 0, 0, 1, 3 ]
Query metrics:
  •    bytesIn:  82

  •   bytesOut:  24

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 4ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!