---
title: "Bit expressions"
description: "Aerospike bitwise expressions covering read and modify operations on blob values, with multi-language examples."
---

# Bit expressions

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

Bit expressions read and modify blob (bytes) values inside an [expression](https://aerospike.com/docs/develop/expressions/) tree: reading bit ranges, counting and scanning bits, resizing or patching bytes, and applying bitwise math without round-tripping the whole blob to the client. For the data type itself and its Operate API, see [Blob (bytes)](https://aerospike.com/docs/develop/data-types/blob/).

Read expressions (`bit_get`, `bit_count`, `bit_lscan`, …) evaluate to an integer, a blob, or a string. That makes them **projection**: they shape what a command returns for each record, in [`operate`](https://aerospike.com/docs/develop/learn/bin-operations/), in a [batch](https://aerospike.com/docs/develop/learn/batch/), and in a [query](https://aerospike.com/docs/develop/learn/queries/projection). Wrap one in [comparison](https://aerospike.com/docs/develop/expressions/comparison) or [logic](https://aerospike.com/docs/develop/expressions/logic) to get the Boolean a record filter needs.

Modify expressions (`bit_set`, `bit_add`, `bit_insert`, …) evaluate to a new blob and leave the record untouched. Storing that value takes a write operation expression; see [Operations and expressions](https://aerospike.com/docs/develop/learn/operations-and-expressions) for how the two APIs differ.

A blob operand is a bin, read with [`bin_blob`](https://aerospike.com/docs/develop/expressions/storage#bin_blob), or any expression that evaluates to a blob. Reading stored data can evaluate to `unknown`; see [Unknown results](https://aerospike.com/docs/develop/expressions#unknown-results).

The examples use a blob bin `device_flags` holding `[0x01, 0x42, 0x03, 0x04, 0x05]`; `bit_b64_encode` uses the Blob reference’s `flags`, `[0x01, 0x42, 0xB0, 0x04, 0x05]`.

The Developer SDK’s [AEL](https://aerospike.com/docs/develop/client/sdk/concepts/ael/reference) text syntax exposes the same bit/blob functions as path methods, for example `$.header.bitGetInt(offset: 0, size: 16)`. See [BLOB (bit) path functions](https://aerospike.com/docs/develop/client/sdk/concepts/ael/reference/type-functions#blob-bit-path-functions).

## Composing expressions

An expression evaluates to a value, and that value is what the next expression operates on — see [Expressions compose](https://aerospike.com/docs/develop/expressions#expressions-compose).

Every bit operation takes its `bin` operand that way: not only a named blob bin, but the result of any expression evaluating to a blob. [`bit_set`](#bit_set) shows the pattern — its example reads the result of a `bit_set` back with [`bit_get`](#bit_get), so the read sees the patched blob while the record keeps the original.

Each operation’s Example shows the code in nine tabs: Aerospike Expression Language (AEL) text on the Java SDK and Python SDK tabs, and the `Exp` builder on the other seven. See the [AEL reference](https://aerospike.com/docs/develop/client/sdk/concepts/ael/reference) for AEL grammar.

## Modify

#### `bit_add`

```python
bit_add(policy, bit_offset, bit_size, value, signed, action, bin)
```

Description: Returns the blob with `value` added to the `bit_size`\-bit big-endian integer starting at `bit_offset`, read as signed or unsigned according to `signed`. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region being added to.

 |
| `bit_size` | `integer` | 

Width of the region in bits, up to 64. This is the width of the integer the addition is performed on, not the width of `value`.

 |
| `value` | `integer` | 

Integer to add. It is converted to a `bit_size`\-bit integer before the addition, so a value too wide for the region is truncated rather than rejected.

 |
| `signed` | `boolean literal` | 

Whether the region is read as a signed or an unsigned integer. This does not change the arithmetic; it decides where the limits sit, and so which results count as overflow. In an 8-bit region, adding 1 to `0x7F` overflows when signed and does not when unsigned; adding 1 to `0xFF` overflows when unsigned and does not when signed.

 |
| `action` | `Overflow action` | 

What happens when the addition crosses the region’s limit: fail, which is the default; saturate at the limit; or wrap around past it. Which values count as crossing depends on `signed`. Supplied by your client as an overflow-action constant.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where adding `1` to the unsigned 8-bit field at bit offset `16` (overflow `FAIL`) matches reading the next byte at offset `24`.

-   [Java SDK](#tab-panel-1138)
-   [Python SDK](#tab-panel-1139)
-   [Rust](#tab-panel-1140)
-   [C#](#tab-panel-1141)
-   [Go](#tab-panel-1142)
-   [Node.js](#tab-panel-1143)
-   [C](#tab-panel-1144)
-   [Java](#tab-panel-1145)
-   [Python](#tab-panel-1146)

```java
String exp = "$.device_flags.bitAdd(offset: 16, size: 8, value: 1)"

    + ".bitGet(offset: 16, size: 8)"

    + " == $.device_flags.bitGet(offset: 24, size: 8)";
```

```python
exp = ("$.device_flags.bitAdd(offset: 16, size: 8, value: 1)"

       ".bitGet(offset: 16, size: 8)"

       " == $.device_flags.bitGet(offset: 24, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy, BitwiseOverflowActions};

let exp = eq(

    bit_exp::get(

        int_val(16),

        int_val(8),

        bit_exp::add(

            &BitPolicy::default(),

            int_val(16),

            int_val(8),

            int_val(1),

            false,

            BitwiseOverflowActions::Fail,

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(24), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(16),

      Exp.Val(8),

      BitExp.Add(

        BitPolicy.Default,

        Exp.Val(16),

        Exp.Val(8),

        Exp.Val(1),

        false,

        BitOverflowAction.FAIL,

        Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(24), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(16),

    as.ExpIntVal(8),

    as.ExpBitAdd(

      as.DefaultBitPolicy(),

      as.ExpIntVal(16),

      as.ExpIntVal(8),

      as.ExpIntVal(1),

      false,

      as.BitOverflowActionFail,

      bin,

    ),

  ),

  as.ExpBitGet(as.ExpIntVal(24), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bits = Aerospike.bitwise

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(

    exp.bit.add(bin, bits.overflow.FAIL, exp.int(1), exp.int(8), exp.int(16)),

    exp.int(8),

    exp.int(16),

  ),

  exp.bit.get(bin, exp.int(8), exp.int(24)),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(16),

      as_exp_int(8),

      as_exp_bit_add(

        NULL,

        as_exp_int(16),

        as_exp_int(8),

        as_exp_int(1),

        AS_BIT_OVERFLOW_FAIL,

        as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(24), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitOverflowAction;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(16),

      Exp.val(8),

      BitExp.add(

          BitPolicy.Default,

          Exp.val(16),

          Exp.val(8),

          Exp.val(1),

          false,

          BitOverflowAction.FAIL,

          Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(24), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
import aerospike

from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitAdd, BitGet

b = BlobBin("device_flags")

exp = Eq(BitGet(16, 8, BitAdd(None, 16, 8, 1, aerospike.BIT_OVERFLOW_FAIL, b)), BitGet(24, 8, b)).compile()
```

---

#### `bit_and`

```python
bit_and(policy, bit_offset, bit_size, value, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` replaced by their bitwise AND with `value`. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `blob` | 

Blob supplying the bits to AND with. Must be at least `bit_size` bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where AND-ing bits 16–23 (`0x03`) with `0x01` leaves `0x01`.

-   [Java SDK](#tab-panel-1147)
-   [Python SDK](#tab-panel-1148)
-   [Rust](#tab-panel-1149)
-   [C#](#tab-panel-1150)
-   [Go](#tab-panel-1151)
-   [Node.js](#tab-panel-1152)
-   [C](#tab-panel-1153)
-   [Java](#tab-panel-1154)
-   [Python](#tab-panel-1155)

```java
String exp = "$.device_flags.bitAnd(offset: 16, size: 8, value: x'01')"

    + ".bitGet(offset: 16, size: 8) == x'01'";
```

```python
exp = ("$.device_flags.bitAnd(offset: 16, size: 8, value: x'01')"

       ".bitGet(offset: 16, size: 8) == x'01'")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(16),

        int_val(8),

        bit_exp::and(

            &BitPolicy::default(),

            int_val(16),

            int_val(8),

            blob_val(vec![0x01]),

            blob_bin("device_flags".into()))),

    blob_val(vec![0x01]));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(16),

      Exp.Val(8),

      BitExp.And(

        BitPolicy.Default,

        Exp.Val(16),

        Exp.Val(8),

        Exp.Val(new byte[] {0x01}),

        Exp.BlobBin("device_flags"))),

    Exp.Val(new byte[] {0x01})));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(16),

    as.ExpIntVal(8),

    as.ExpBitAnd(as.DefaultBitPolicy(), as.ExpIntVal(16), as.ExpIntVal(8), as.ExpBlobVal([]byte{0x01}), bin),

  ),

  as.ExpBlobVal([]byte{0x01}),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.and(bin, exp.bytes(Buffer.from([0x01])), exp.int(8), exp.int(16)), exp.int(8), exp.int(16)),

  exp.bytes(Buffer.from([0x01])),

)
```

```c
uint8_t v[] = {0x01};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(16),

      as_exp_int(8),

      as_exp_bit_and(

        NULL,

        as_exp_int(16),

        as_exp_int(8),

        as_exp_bytes(v, sizeof(v)),

        as_exp_bin_blob("device_flags"))),

    as_exp_bytes(v, sizeof(v))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(16),

      Exp.val(8),

      BitExp.and(

          BitPolicy.Default,

          Exp.val(16),

          Exp.val(8),

          Exp.val(new byte[] {0x01}),

          Exp.blobBin("device_flags"))),

    Exp.val(new byte[] {0x01})));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitAnd, BitGet

b = BlobBin("device_flags")

exp = Eq(BitGet(16, 8, BitAnd(None, 16, 8, bytearray([0x01]), b)), bytearray([0x01])).compile()
```

---

#### `bit_insert`

```python
bit_insert(policy, byte_offset, blob, bin)
```

Description: Returns the blob with `blob` inserted at `byte_offset`, growing it by the length of `blob`.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `byte_offset` | `integer` | 

Offset in bytes from the start of the blob at which to insert.

 |
| `blob` | `blob` | 

Bytes to insert.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where inserting `0xFF` at byte offset `1` makes the unsigned 8-bit integer at bit offset `8` equal `0xFF`.

-   [Java SDK](#tab-panel-1156)
-   [Python SDK](#tab-panel-1157)
-   [Rust](#tab-panel-1158)
-   [C#](#tab-panel-1159)
-   [Go](#tab-panel-1160)
-   [Node.js](#tab-panel-1161)
-   [C](#tab-panel-1162)
-   [Java](#tab-panel-1163)
-   [Python](#tab-panel-1164)

```java
String exp = "$.device_flags.bitInsert(byteOffset: 1, value: x'ff')"

    + ".bitGetInt(offset: 8, size: 8) == 0xff";
```

```python
exp = ("$.device_flags.bitInsert(byteOffset: 1, value: x'ff')"

       ".bitGetInt(offset: 8, size: 8) == 0xff")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get_int(

        int_val(8),

        int_val(8),

        false,

        bit_exp::insert(

            &BitPolicy::default(),

            int_val(1),

            blob_val(vec![0xff]),

            blob_bin("device_flags".into()))),

    int_val(0xff));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.GetInt(

      Exp.Val(8),

      Exp.Val(8),

      false,

      BitExp.Insert(BitPolicy.Default, Exp.Val(1), Exp.Val(new byte[] {0xFF}), Exp.BlobBin("device_flags"))),

    Exp.Val(0xFF)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitGetInt(

    as.ExpIntVal(8),

    as.ExpIntVal(8),

    false,

    as.ExpBitInsert(as.DefaultBitPolicy(), as.ExpIntVal(1), as.ExpBlobVal([]byte{0xff}), as.ExpBlobBin("device_flags")),

  ),

  as.ExpIntVal(0xff),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.getInt(

    exp.bit.insert(exp.binBlob('device_flags'), exp.bytes(Buffer.from([0xff])), exp.int(1)),

    false,

    exp.int(8),

    exp.int(8),

  ),

  exp.int(0xff),

)
```

```c
uint8_t ins[] = {0xff};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get_int(

      as_exp_int(8),

      as_exp_int(8),

      false,

      as_exp_bit_insert(

        NULL, as_exp_int(1), as_exp_bytes(ins, sizeof(ins)), as_exp_bin_blob("device_flags"))),

    as_exp_int(0xff)));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.getInt(

      Exp.val(8),

      Exp.val(8),

      false,

      BitExp.insert(

          BitPolicy.Default,

          Exp.val(1),

          Exp.val(new byte[] {(byte) 0xff}),

          Exp.blobBin("device_flags"))),

    Exp.val(0xff)));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGetInt, BitInsert

exp = Eq(

  BitGetInt(8, 8, False, BitInsert(None, 1, bytearray([0xFF]), BlobBin("device_flags"))),

  0xFF,

).compile()
```

---

#### `bit_lshift`

```python
bit_lshift(policy, bit_offset, bit_size, shift, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` shifted left by `shift`, filling from the right with zeros. Bits shifted out of the region are discarded. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `shift` | `integer` | 

Number of bit positions to shift by.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where shifting the first byte left by two bits preserves the following six bits relative to the unmodified blob.

-   [Java SDK](#tab-panel-1165)
-   [Python SDK](#tab-panel-1166)
-   [Rust](#tab-panel-1167)
-   [C#](#tab-panel-1168)
-   [Go](#tab-panel-1169)
-   [Node.js](#tab-panel-1170)
-   [C](#tab-panel-1171)
-   [Java](#tab-panel-1172)
-   [Python](#tab-panel-1173)

```java
String exp = "$.device_flags.bitLshift(offset: 0, size: 8, shift: 2)"

    + ".bitGet(offset: 0, size: 6)"

    + " == $.device_flags.bitGet(offset: 2, size: 6)";
```

```python
exp = ("$.device_flags.bitLshift(offset: 0, size: 8, shift: 2)"

       ".bitGet(offset: 0, size: 6)"

       " == $.device_flags.bitGet(offset: 2, size: 6)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(0),

        int_val(6),

        bit_exp::lshift(

            &BitPolicy::default(),

            int_val(0),

            int_val(8),

            int_val(2),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(2), int_val(6), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(0),

      Exp.Val(6),

      BitExp.Lshift(

        BitPolicy.Default, Exp.Val(0), Exp.Val(8), Exp.Val(2), Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(2), Exp.Val(6), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(0),

    as.ExpIntVal(6),

    as.ExpBitLShift(as.DefaultBitPolicy(), as.ExpIntVal(0), as.ExpIntVal(8), as.ExpIntVal(2), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(2), as.ExpIntVal(6), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.lShift(bin, exp.int(2), exp.int(8), exp.int(0)), exp.int(6), exp.int(0)),

  exp.bit.get(bin, exp.int(6), exp.int(2)),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(0),

      as_exp_int(6),

      as_exp_bit_lshift(

        NULL, as_exp_int(0), as_exp_int(8), as_exp_int(2), as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(2), as_exp_int(6), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(0),

      Exp.val(6),

      BitExp.lshift(

          BitPolicy.Default, Exp.val(0), Exp.val(8), Exp.val(2), Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(2), Exp.val(6), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitLeftShift

b = BlobBin("device_flags")

exp = Eq(BitGet(0, 6, BitLeftShift(None, 0, 8, 2, b)), BitGet(2, 6, b)).compile()
```

---

#### `bit_not`

```python
bit_not(policy, bit_offset, bit_size, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` replaced by their bitwise complement. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where NOT-ing one bit at offset `6` makes the first byte match bits 16–23 of the original blob (`0x03`).

-   [Java SDK](#tab-panel-1174)
-   [Python SDK](#tab-panel-1175)
-   [Rust](#tab-panel-1176)
-   [C#](#tab-panel-1177)
-   [Go](#tab-panel-1178)
-   [Node.js](#tab-panel-1179)
-   [C](#tab-panel-1180)
-   [Java](#tab-panel-1181)
-   [Python](#tab-panel-1182)

```java
String exp = "$.device_flags.bitNot(offset: 6, size: 1)"

    + ".bitGet(offset: 0, size: 8)"

    + " == $.device_flags.bitGet(offset: 16, size: 8)";
```

```python
exp = ("$.device_flags.bitNot(offset: 6, size: 1)"

       ".bitGet(offset: 0, size: 8)"

       " == $.device_flags.bitGet(offset: 16, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(0),

        int_val(8),

        bit_exp::not(

            &BitPolicy::default(),

            int_val(6),

            int_val(1),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(16), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(0),

      Exp.Val(8),

      BitExp.Not(BitPolicy.Default, Exp.Val(6), Exp.Val(1), Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(0),

    as.ExpIntVal(8),

    as.ExpBitNot(as.DefaultBitPolicy(), as.ExpIntVal(6), as.ExpIntVal(1), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(16), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.not(bin, exp.int(1), exp.int(6)), exp.int(8), exp.int(0)),

  exp.bit.get(bin, exp.int(8), exp.int(16)),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(0),

      as_exp_int(8),

      as_exp_bit_not(NULL, as_exp_int(6), as_exp_int(1), as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(16), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(0),

      Exp.val(8),

      BitExp.not(BitPolicy.Default, Exp.val(6), Exp.val(1), Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitNot

b = BlobBin("device_flags")

exp = Eq(BitGet(0, 8, BitNot(None, 6, 1, b)), BitGet(16, 8, b)).compile()
```

---

#### `bit_or`

```python
bit_or(policy, bit_offset, bit_size, value, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` replaced by their bitwise OR with `value`. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `blob` | 

Blob supplying the bits to OR with. Must be at least `bit_size` bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where OR-ing `0x01` into bits 24–31 makes the 8-bit slice at offset `24` match the slice at offset `32`.

-   [Java SDK](#tab-panel-1183)
-   [Python SDK](#tab-panel-1184)
-   [Rust](#tab-panel-1185)
-   [C#](#tab-panel-1186)
-   [Go](#tab-panel-1187)
-   [Node.js](#tab-panel-1188)
-   [C](#tab-panel-1189)
-   [Java](#tab-panel-1190)
-   [Python](#tab-panel-1191)

```java
String exp = "$.device_flags.bitOr(offset: 24, size: 8, value: x'01')"

    + ".bitGet(offset: 24, size: 8)"

    + " == $.device_flags.bitGet(offset: 32, size: 8)";
```

```python
exp = ("$.device_flags.bitOr(offset: 24, size: 8, value: x'01')"

       ".bitGet(offset: 24, size: 8)"

       " == $.device_flags.bitGet(offset: 32, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(24),

        int_val(8),

        bit_exp::or(

            &BitPolicy::default(),

            int_val(24),

            int_val(8),

            blob_val(vec![0x01]),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(32), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(24),

      Exp.Val(8),

      BitExp.Or(

        BitPolicy.Default,

        Exp.Val(24),

        Exp.Val(8),

        Exp.Val(new byte[] {0x01}),

        Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(32), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(24),

    as.ExpIntVal(8),

    as.ExpBitOr(as.DefaultBitPolicy(), as.ExpIntVal(24), as.ExpIntVal(8), as.ExpBlobVal([]byte{0x01}), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(32), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.or(bin, exp.bytes(Buffer.from([0x01])), exp.int(8), exp.int(24)), exp.int(8), exp.int(24)),

  exp.bit.get(bin, exp.int(8), exp.int(32)),

)
```

```c
uint8_t v[] = {0x01};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(24),

      as_exp_int(8),

      as_exp_bit_or(

        NULL,

        as_exp_int(24),

        as_exp_int(8),

        as_exp_bytes(v, sizeof(v)),

        as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(32), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(24),

      Exp.val(8),

      BitExp.or(

          BitPolicy.Default,

          Exp.val(24),

          Exp.val(8),

          Exp.val(new byte[] {0x01}),

          Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(32), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitOr

b = BlobBin("device_flags")

exp = Eq(BitGet(24, 8, BitOr(None, 24, 8, bytearray([0x01]), b)), BitGet(32, 8, b)).compile()
```

---

#### `bit_remove`

```python
bit_remove(policy, byte_offset, byte_size, bin)
```

Description: Returns the blob with `byte_size` bytes removed starting at `byte_offset`, shrinking it by that many bytes.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `byte_offset` | `integer` | 

Offset in bytes from the start of the blob at which to start removing.

 |
| `byte_size` | `integer` | 

Number of bytes to remove.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where removing the first byte leaves `0x42` as the unsigned 8-bit value at bit offset `0`.

-   [Java SDK](#tab-panel-1192)
-   [Python SDK](#tab-panel-1193)
-   [Rust](#tab-panel-1194)
-   [C#](#tab-panel-1195)
-   [Go](#tab-panel-1196)
-   [Node.js](#tab-panel-1197)
-   [C](#tab-panel-1198)
-   [Java](#tab-panel-1199)
-   [Python](#tab-panel-1200)

```java
String exp = "$.device_flags.bitRemove(byteOffset: 0, byteSize: 1)"

    + ".bitGetInt(offset: 0, size: 8) == 0x42";
```

```python
exp = ("$.device_flags.bitRemove(byteOffset: 0, byteSize: 1)"

       ".bitGetInt(offset: 0, size: 8) == 0x42")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get_int(

        int_val(0),

        int_val(8),

        false,

        bit_exp::remove(

            &BitPolicy::default(),

            int_val(0),

            int_val(1),

            blob_bin("device_flags".into()))),

    int_val(0x42));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.GetInt(

      Exp.Val(0),

      Exp.Val(8),

      false,

      BitExp.Remove(BitPolicy.Default, Exp.Val(0), Exp.Val(1), Exp.BlobBin("device_flags"))),

    Exp.Val(0x42)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitGetInt(

    as.ExpIntVal(0),

    as.ExpIntVal(8),

    false,

    as.ExpBitRemove(as.DefaultBitPolicy(), as.ExpIntVal(0), as.ExpIntVal(1), as.ExpBlobBin("device_flags")),

  ),

  as.ExpIntVal(0x42),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.getInt(

    exp.bit.remove(exp.binBlob('device_flags'), exp.int(1), exp.int(0)),

    false,

    exp.int(8),

    exp.int(0),

  ),

  exp.int(0x42),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get_int(

      as_exp_int(0),

      as_exp_int(8),

      0,

      as_exp_bit_remove(NULL, as_exp_int(0), as_exp_int(1), as_exp_bin_blob("device_flags"))),

    as_exp_int(0x42)));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.getInt(

      Exp.val(0),

      Exp.val(8),

      false,

      BitExp.remove(BitPolicy.Default, Exp.val(0), Exp.val(1), Exp.blobBin("device_flags"))),

    Exp.val(0x42)));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGetInt, BitRemove

exp = Eq(BitGetInt(0, 8, False, BitRemove(None, 0, 1, BlobBin("device_flags"))), 0x42).compile()
```

---

#### `bit_resize`

```python
bit_resize(policy, byte_size, resize_flags, bin)
```

Description: Returns the blob resized to `byte_size` bytes. Growing pads with zero bytes at the end and shrinking drops bytes from the end; `resize_flags` can work at the front instead, or forbid growing or shrinking.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `byte_size` | `integer` | 

New size of the blob in bytes.

 |
| `resize_flags` | `Resize flags` | 

Where bytes are added or dropped, and whether both directions are allowed: by default at the end, with `from_front` working at the beginning instead, `grow_only` forbidding shrinking, and `shrink_only` forbidding growing.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where the first byte after resizing `device_flags` to six bytes (default resize flags) is still `0x01` — modify expressions evaluate on a temporary blob value.

-   [Java SDK](#tab-panel-1201)
-   [Python SDK](#tab-panel-1202)
-   [Rust](#tab-panel-1203)
-   [C#](#tab-panel-1204)
-   [Go](#tab-panel-1205)
-   [Node.js](#tab-panel-1206)
-   [C](#tab-panel-1207)
-   [Java](#tab-panel-1208)
-   [Python](#tab-panel-1209)

```java
String exp = "$.device_flags.bitResize(byteSize: 6)"

    + ".bitGet(offset: 0, size: 8) == x'01'";
```

```python
exp = ("$.device_flags.bitResize(byteSize: 6)"

       ".bitGet(offset: 0, size: 8) == x'01'")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy, BitwiseResizeFlags};

let exp = eq(

    bit_exp::get(

        int_val(0),

        int_val(8),

        bit_exp::resize(

            &BitPolicy::default(),

            int_val(6),

            BitwiseResizeFlags::Default,

            blob_bin("device_flags".into()))),

    blob_val(vec![0x01]));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(0),

      Exp.Val(8),

      BitExp.Resize(BitPolicy.Default, Exp.Val(6), 0, Exp.BlobBin("device_flags"))),

    Exp.Val(new byte[] {0x01})));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(0),

    as.ExpIntVal(8),

    as.ExpBitResize(as.DefaultBitPolicy(), as.ExpIntVal(6), as.BitResizeFlagsDefault, as.ExpBlobBin("device_flags")),

  ),

  as.ExpBlobVal([]byte{0x01}),

)
```

```javascript
const exp = Aerospike.exp

const bits = Aerospike.bitwise

const filterExp = exp.eq(

  exp.bit.get(

    exp.bit.reSize(exp.binBlob('device_flags'), bits.resizeFlags.DEFAULT, exp.int(6)),

    exp.int(8),

    exp.int(0),

  ),

  exp.bytes(Buffer.from([0x01])),

)
```

```c
uint8_t want[] = {0x01};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(0),

      as_exp_int(8),

      as_exp_bit_resize(NULL, as_exp_int(6), 0, as_exp_bin_blob("device_flags"))),

    as_exp_bytes(want, sizeof(want))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(0),

      Exp.val(8),

      BitExp.resize(BitPolicy.Default, Exp.val(6), 0, Exp.blobBin("device_flags"))),

    Exp.val(new byte[] {0x01})));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitResize

exp = Eq(BitGet(0, 8, BitResize(None, 6, 0, BlobBin("device_flags"))), bytearray([0x01])).compile()
```

---

#### `bit_rshift`

```python
bit_rshift(policy, bit_offset, bit_size, shift, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` shifted right by `shift`, filling from the left with zeros. Bits shifted out of the region are discarded. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `shift` | `integer` | 

Number of bit positions to shift by.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where shifting bits 24–31 right by two leaves the following six bits unchanged relative to the original blob.

-   [Java SDK](#tab-panel-1210)
-   [Python SDK](#tab-panel-1211)
-   [Rust](#tab-panel-1212)
-   [C#](#tab-panel-1213)
-   [Go](#tab-panel-1214)
-   [Node.js](#tab-panel-1215)
-   [C](#tab-panel-1216)
-   [Java](#tab-panel-1217)
-   [Python](#tab-panel-1218)

```java
String exp = "$.device_flags.bitRshift(offset: 24, size: 8, shift: 2)"

    + ".bitGet(offset: 26, size: 6)"

    + " == $.device_flags.bitGet(offset: 24, size: 6)";
```

```python
exp = ("$.device_flags.bitRshift(offset: 24, size: 8, shift: 2)"

       ".bitGet(offset: 26, size: 6)"

       " == $.device_flags.bitGet(offset: 24, size: 6)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(26),

        int_val(6),

        bit_exp::rshift(

            &BitPolicy::default(),

            int_val(24),

            int_val(8),

            int_val(2),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(24), int_val(6), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(26),

      Exp.Val(6),

      BitExp.Rshift(

        BitPolicy.Default, Exp.Val(24), Exp.Val(8), Exp.Val(2), Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(24), Exp.Val(6), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(26),

    as.ExpIntVal(6),

    as.ExpBitRShift(as.DefaultBitPolicy(), as.ExpIntVal(24), as.ExpIntVal(8), as.ExpIntVal(2), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(24), as.ExpIntVal(6), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.rShift(bin, exp.int(2), exp.int(8), exp.int(24)), exp.int(6), exp.int(26)),

  exp.bit.get(bin, exp.int(6), exp.int(24)),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(26),

      as_exp_int(6),

      as_exp_bit_rshift(

        NULL, as_exp_int(24), as_exp_int(8), as_exp_int(2), as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(24), as_exp_int(6), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(26),

      Exp.val(6),

      BitExp.rshift(

          BitPolicy.Default, Exp.val(24), Exp.val(8), Exp.val(2), Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(24), Exp.val(6), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitRightShift

b = BlobBin("device_flags")

exp = Eq(BitGet(26, 6, BitRightShift(None, 24, 8, 2, b)), BitGet(24, 6, b)).compile()
```

---

#### `bit_set`

```python
bit_set(policy, bit_offset, bit_size, value, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` replaced by the leading `bit_size` bits of `value`. `value` must supply at least that many bits. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `blob` | 

Blob supplying the replacement bits, taken from its leading bits. Must be at least `bit_size` bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where setting one bit at offset `31` makes the 8-bit slice at offset `24` match the original slice at offset `32`.

-   [Java SDK](#tab-panel-1219)
-   [Python SDK](#tab-panel-1220)
-   [Rust](#tab-panel-1221)
-   [C#](#tab-panel-1222)
-   [Go](#tab-panel-1223)
-   [Node.js](#tab-panel-1224)
-   [C](#tab-panel-1225)
-   [Java](#tab-panel-1226)
-   [Python](#tab-panel-1227)

```java
String exp = "$.device_flags.bitSet(offset: 31, size: 1, value: x'80')"

    + ".bitGet(offset: 24, size: 8)"

    + " == $.device_flags.bitGet(offset: 32, size: 8)";
```

```python
exp = ("$.device_flags.bitSet(offset: 31, size: 1, value: x'80')"

       ".bitGet(offset: 24, size: 8)"

       " == $.device_flags.bitGet(offset: 32, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(24),

        int_val(8),

        bit_exp::set(

            &BitPolicy::default(),

            int_val(31),

            int_val(1),

            blob_val(vec![0x80]),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(32), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(24),

      Exp.Val(8),

      BitExp.Set(

        BitPolicy.Default,

        Exp.Val(31),

        Exp.Val(1),

        Exp.Val(new byte[] {0x80}),

        Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(32), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(24),

    as.ExpIntVal(8),

    as.ExpBitSet(as.DefaultBitPolicy(), as.ExpIntVal(31), as.ExpIntVal(1), as.ExpBlobVal([]byte{0x80}), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(32), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.set(bin, exp.bytes(Buffer.from([0x80])), exp.int(1), exp.int(31)), exp.int(8), exp.int(24)),

  exp.bit.get(bin, exp.int(8), exp.int(32)),

)
```

```c
uint8_t v[] = {0x80};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(24),

      as_exp_int(8),

      as_exp_bit_set(

        NULL,

        as_exp_int(31),

        as_exp_int(1),

        as_exp_bytes(v, sizeof(v)),

        as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(32), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(24),

      Exp.val(8),

      BitExp.set(

          BitPolicy.Default,

          Exp.val(31),

          Exp.val(1),

          Exp.val(new byte[] {(byte) 0x80}),

          Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(32), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitSet

b = BlobBin("device_flags")

exp = Eq(

  BitGet(24, 8, BitSet(None, 31, 1, bytearray([0x80]), b)),

  BitGet(32, 8, b),

).compile()
```

---

#### `bit_set_int`

```python
bit_set_int(policy, bit_offset, bit_size, value, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` replaced by `value`, written as a big-endian integer of that width. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `integer` | 

Integer to write into the region.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where writing integer `0x42` into bits 24–31 makes that 8-bit slice match the original second byte of `device_flags`.

-   [Java SDK](#tab-panel-1228)
-   [Python SDK](#tab-panel-1229)
-   [Rust](#tab-panel-1230)
-   [C#](#tab-panel-1231)
-   [Go](#tab-panel-1232)
-   [Node.js](#tab-panel-1233)
-   [C](#tab-panel-1234)
-   [Java](#tab-panel-1235)
-   [Python](#tab-panel-1236)

```java
String exp = "$.device_flags.bitSetInt(offset: 24, size: 8, value: 0x42)"

    + ".bitGet(offset: 24, size: 8)"

    + " == $.device_flags.bitGet(offset: 8, size: 8)";
```

```python
exp = ("$.device_flags.bitSetInt(offset: 24, size: 8, value: 0x42)"

       ".bitGet(offset: 24, size: 8)"

       " == $.device_flags.bitGet(offset: 8, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(24),

        int_val(8),

        bit_exp::set_int(

            &BitPolicy::default(),

            int_val(24),

            int_val(8),

            int_val(0x42),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(8), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(24),

      Exp.Val(8),

      BitExp.SetInt(

        BitPolicy.Default, Exp.Val(24), Exp.Val(8), Exp.Val(0x42), Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(8), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(24),

    as.ExpIntVal(8),

    as.ExpBitSetInt(as.DefaultBitPolicy(), as.ExpIntVal(24), as.ExpIntVal(8), as.ExpIntVal(0x42), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(8), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.setInt(bin, exp.int(0x42), exp.int(8), exp.int(24)), exp.int(8), exp.int(24)),

  exp.bit.get(bin, exp.int(8), exp.int(8)),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(24),

      as_exp_int(8),

      as_exp_bit_set_int(

        NULL, as_exp_int(24), as_exp_int(8), as_exp_int(0x42), as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(8), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(24),

      Exp.val(8),

      BitExp.setInt(

          BitPolicy.Default, Exp.val(24), Exp.val(8), Exp.val(0x42), Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(8), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitSetInt

b = BlobBin("device_flags")

exp = Eq(BitGet(24, 8, BitSetInt(None, 24, 8, 0x42, b)), BitGet(8, 8, b)).compile()
```

---

#### `bit_subtract`

```python
bit_subtract(policy, bit_offset, bit_size, value, signed, action, bin)
```

Description: Returns the blob with `value` subtracted from the `bit_size`\-bit big-endian integer starting at `bit_offset`, read as signed or unsigned according to `signed`. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `integer` | 

Integer to subtract. It is converted to a `bit_size`\-bit integer first.

 |
| `signed` | `boolean literal` | 

Whether the region is read as a signed or an unsigned integer. This does not change the arithmetic; it decides where the limits sit, and so which results count as overflow. In an 8-bit region, adding 1 to `0x7F` overflows when signed and does not when unsigned; adding 1 to `0xFF` overflows when unsigned and does not when signed.

 |
| `action` | `Overflow action` | 

What happens when the subtraction crosses the region’s limit: fail, which is the default; saturate at the limit; or wrap around past it. Which values count as crossing depends on `signed`. Supplied by your client as an overflow-action constant.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where subtracting `1` from the unsigned 8-bit field at bit offset `24` (overflow `FAIL`) matches the field at offset `16`.

-   [Java SDK](#tab-panel-1237)
-   [Python SDK](#tab-panel-1238)
-   [Rust](#tab-panel-1239)
-   [C#](#tab-panel-1240)
-   [Go](#tab-panel-1241)
-   [Node.js](#tab-panel-1242)
-   [C](#tab-panel-1243)
-   [Java](#tab-panel-1244)
-   [Python](#tab-panel-1245)

```java
String exp = "$.device_flags.bitSubtract(offset: 24, size: 8, value: 1)"

    + ".bitGet(offset: 24, size: 8)"

    + " == $.device_flags.bitGet(offset: 16, size: 8)";
```

```python
exp = ("$.device_flags.bitSubtract(offset: 24, size: 8, value: 1)"

       ".bitGet(offset: 24, size: 8)"

       " == $.device_flags.bitGet(offset: 16, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy, BitwiseOverflowActions};

let exp = eq(

    bit_exp::get(

        int_val(24),

        int_val(8),

        bit_exp::subtract(

            &BitPolicy::default(),

            int_val(24),

            int_val(8),

            int_val(1),

            false,

            BitwiseOverflowActions::Fail,

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(16), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(24),

      Exp.Val(8),

      BitExp.Subtract(

        BitPolicy.Default,

        Exp.Val(24),

        Exp.Val(8),

        Exp.Val(1),

        false,

        BitOverflowAction.FAIL,

        Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(24),

    as.ExpIntVal(8),

    as.ExpBitSubtract(

      as.DefaultBitPolicy(),

      as.ExpIntVal(24),

      as.ExpIntVal(8),

      as.ExpIntVal(1),

      false,

      as.BitOverflowActionFail,

      bin,

    ),

  ),

  as.ExpBitGet(as.ExpIntVal(16), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bits = Aerospike.bitwise

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(

    exp.bit.subtract(bin, bits.overflow.FAIL, exp.int(1), exp.int(8), exp.int(24)),

    exp.int(8),

    exp.int(24),

  ),

  exp.bit.get(bin, exp.int(8), exp.int(16)),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(24),

      as_exp_int(8),

      as_exp_bit_subtract(

        NULL,

        as_exp_int(24),

        as_exp_int(8),

        as_exp_int(1),

        AS_BIT_OVERFLOW_FAIL,

        as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(16), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitOverflowAction;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(24),

      Exp.val(8),

      BitExp.subtract(

          BitPolicy.Default,

          Exp.val(24),

          Exp.val(8),

          Exp.val(1),

          false,

          BitOverflowAction.FAIL,

          Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
import aerospike

from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitSubtract

b = BlobBin("device_flags")

exp = Eq(BitGet(24, 8, BitSubtract(None, 24, 8, 1, aerospike.BIT_OVERFLOW_FAIL, b)), BitGet(16, 8, b)).compile()
```

---

#### `bit_xor`

```python
bit_xor(policy, bit_offset, bit_size, value, bin)
```

Description: Returns the blob with the `bit_size` bits at `bit_offset` replaced by their bitwise XOR with `value`. The rest of the blob is unchanged, and its length does not change.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `Bit policy` | 
Write policy for the transform. Supplied by your client as a blob or bitwise policy object.

 |
| `bit_offset` | `integer` | 

Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `blob` | 

Blob supplying the bits to XOR with. Must be at least `bit_size` bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where XOR-ing the first byte with `0x02` yields the same 8-bit slice as bits 16–23 of the original `device_flags`.

-   [Java SDK](#tab-panel-1246)
-   [Python SDK](#tab-panel-1247)
-   [Rust](#tab-panel-1248)
-   [C#](#tab-panel-1249)
-   [Go](#tab-panel-1250)
-   [Node.js](#tab-panel-1251)
-   [C](#tab-panel-1252)
-   [Java](#tab-panel-1253)
-   [Python](#tab-panel-1254)

```java
String exp = "$.device_flags.bitXor(offset: 0, size: 8, value: x'02')"

    + ".bitGet(offset: 0, size: 8)"

    + " == $.device_flags.bitGet(offset: 16, size: 8)";
```

```python
exp = ("$.device_flags.bitXor(offset: 0, size: 8, value: x'02')"

       ".bitGet(offset: 0, size: 8)"

       " == $.device_flags.bitGet(offset: 16, size: 8)")
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

use aerospike::operations::bitwise::{BitPolicy};

let exp = eq(

    bit_exp::get(

        int_val(0),

        int_val(8),

        bit_exp::xor(

            &BitPolicy::default(),

            int_val(0),

            int_val(8),

            blob_val(vec![0x02]),

            blob_bin("device_flags".into()))),

    bit_exp::get(int_val(16), int_val(8), blob_bin("device_flags".into())));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(0),

      Exp.Val(8),

      BitExp.Xor(

        BitPolicy.Default,

        Exp.Val(0),

        Exp.Val(8),

        Exp.Val(new byte[] {0x02}),

        Exp.BlobBin("device_flags"))),

    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin("device_flags"))));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

bin := as.ExpBlobBin("device_flags")

exp := as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(0),

    as.ExpIntVal(8),

    as.ExpBitXor(as.DefaultBitPolicy(), as.ExpIntVal(0), as.ExpIntVal(8), as.ExpBlobVal([]byte{0x02}), bin),

  ),

  as.ExpBitGet(as.ExpIntVal(16), as.ExpIntVal(8), bin),

)
```

```javascript
const exp = Aerospike.exp

const bin = exp.binBlob('device_flags')

const filterExp = exp.eq(

  exp.bit.get(exp.bit.xor(bin, exp.bytes(Buffer.from([0x02])), exp.int(8), exp.int(0)), exp.int(8), exp.int(0)),

  exp.bit.get(bin, exp.int(8), exp.int(16)),

)
```

```c
uint8_t v[] = {0x02};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(0),

      as_exp_int(8),

      as_exp_bit_xor(

        NULL,

        as_exp_int(0),

        as_exp_int(8),

        as_exp_bytes(v, sizeof(v)),

        as_exp_bin_blob("device_flags"))),

    as_exp_bit_get(as_exp_int(16), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.operation.BitPolicy;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(

      Exp.val(0),

      Exp.val(8),

      BitExp.xor(

          BitPolicy.Default,

          Exp.val(0),

          Exp.val(8),

          Exp.val(new byte[] {0x02}),

          Exp.blobBin("device_flags"))),

    BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags"))));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet, BitXor

b = BlobBin("device_flags")

exp = Eq(BitGet(0, 8, BitXor(None, 0, 8, bytearray([0x02]), b)), BitGet(16, 8, b)).compile()
```

---

## Read

#### `bit_b64_encode`

```python
bit_b64_encode(byte_offset, byte_size, invert_size, bin)
```

Description: Returns the `byte_size` bytes starting at `byte_offset`, base64 encoded as a string. With `invert_size`, `byte_size` counts back from the end of the blob instead, so the span runs from `byte_offset` to that many bytes before the end.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `byte_offset` | `integer` | 
Offset in bytes from the start of the blob.

 |
| `byte_size` | `integer` | 

Number of bytes to encode. When `invert_size` is true, this is instead the number of bytes to omit from the end.

 |
| `invert_size` | `boolean literal` | 

When true, `byte_size` is the number of bytes to omit from the end of the blob rather than the number to encode, so the span runs from `byte_offset` to `byte_size` bytes before the end.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `string`

Introduced: 8.2.0

Example: Filter where the base64 text of the whole `flags` bin equals `AUKwBAU=` (the 5-byte `[0x01, 0x42, 0xB0, 0x04, 0x05]` pattern used throughout the Blob reference).

-   [Java SDK](#tab-panel-1255)
-   [Python SDK](#tab-panel-1256)
-   [Rust](#tab-panel-1257)
-   [C#](#tab-panel-1258)
-   [Go](#tab-panel-1259)
-   [Node.js](#tab-panel-1260)
-   [C](#tab-panel-1261)
-   [Java](#tab-panel-1262)
-   [Python](#tab-panel-1263)

```java
String exp = "$.flags.b64Encode() == 'AUKwBAU='";
```

```python
exp = "$.flags.b64Encode() == 'AUKwBAU='"
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, string_val};

let exp = eq(

    bit_exp::b64_encode(blob_bin("flags".into())),

    string_val("AUKwBAU=".into()));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.B64Encode(Exp.BlobBin("flags")),

    Exp.Val("AUKwBAU=")));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitB64Encode(as.ExpBlobBin("flags")),

  as.ExpStringVal("AUKwBAU="),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.b64Encode(exp.binBlob('flags')),

  exp.str('AUKwBAU='),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_b64_encode(as_exp_bin_blob("flags")),

    as_exp_str("AUKwBAU=")));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.b64Encode(Exp.blobBin("flags")),

    Exp.val("AUKwBAU=")));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitB64Encode

exp = Eq(BitB64Encode(0, None, False, BlobBin("flags")), "AUKwBAU=").compile()
```

---

#### `bit_count`

```python
bit_count(bit_offset, bit_size, bin)
```

Description: Returns the number of bits set to 1 in the `bit_size` bits starting at `bit_offset`.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bit_offset` | `integer` | 
Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Filter where the second byte of `device_flags` (bits 8–15) has more than one bit set (`0x42`).

-   [Java SDK](#tab-panel-1264)
-   [Python SDK](#tab-panel-1265)
-   [Rust](#tab-panel-1266)
-   [C#](#tab-panel-1267)
-   [Go](#tab-panel-1268)
-   [Node.js](#tab-panel-1269)
-   [C](#tab-panel-1270)
-   [Java](#tab-panel-1271)
-   [Python](#tab-panel-1272)

```java
String exp = "$.device_flags.bitCount(offset: 8, size: 8) > 1";
```

```python
exp = "$.device_flags.bitCount(offset: 8, size: 8) > 1"
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, gt, int_val};

let exp = gt(

    bit_exp::count(int_val(8), int_val(8), blob_bin("device_flags".into())),

    int_val(1));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(BitExp.Count(Exp.Val(8), Exp.Val(8), Exp.BlobBin("device_flags")), Exp.Val(1)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpGreater(

  as.ExpBitCount(as.ExpIntVal(8), as.ExpIntVal(8), as.ExpBlobBin("device_flags")),

  as.ExpIntVal(1),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.gt(

  exp.bit.count(exp.binBlob('device_flags'), exp.int(8), exp.int(8)),

  exp.int(1),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_bit_count(as_exp_int(8), as_exp_int(8), as_exp_bin_blob("device_flags")),

    as_exp_int(1)));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

Expression exp = Exp.build(

  Exp.gt(BitExp.count(Exp.val(8), Exp.val(8), Exp.blobBin("device_flags")), Exp.val(1)));
```

```python
from aerospike_helpers.expressions import BlobBin, GT

from aerospike_helpers.expressions.bitwise import BitCount

exp = GT(BitCount(8, 8, BlobBin("device_flags")), 1).compile()
```

---

#### `bit_get`

```python
bit_get(bit_offset, bit_size, bin)
```

Description: Returns the `bit_size` bits starting at `bit_offset`, as a blob.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bit_offset` | `integer` | 
Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `blob`

Introduced: 5.2.0.4

Example: Filter where bits 16–23 of blob bin `device_flags` read as one byte equal `0x03`.

-   [Java SDK](#tab-panel-1273)
-   [Python SDK](#tab-panel-1274)
-   [Rust](#tab-panel-1275)
-   [C#](#tab-panel-1276)
-   [Go](#tab-panel-1277)
-   [Node.js](#tab-panel-1278)
-   [C](#tab-panel-1279)
-   [Java](#tab-panel-1280)
-   [Python](#tab-panel-1281)

```java
String exp = "$.device_flags.bitGet(offset: 16, size: 8) == x'03'";
```

```python
exp = "$.device_flags.bitGet(offset: 16, size: 8) == x'03'"
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, blob_val, eq, int_val};

let exp = eq(

    bit_exp::get(int_val(16), int_val(8), blob_bin("device_flags".into())),

    blob_val(vec![0x03]));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(Exp.Val(16), Exp.Val(8), Exp.BlobBin("device_flags")),

    Exp.Val(new byte[] {0x03})));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitGet(as.ExpIntVal(16), as.ExpIntVal(8), as.ExpBlobBin("device_flags")),

  as.ExpBlobVal([]byte{0x03}),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.get(exp.binBlob('device_flags'), exp.int(8), exp.int(16)),

  exp.bytes(Buffer.from([0x03])),

)
```

```c
uint8_t want[] = {0x03};

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(as_exp_int(16), as_exp_int(8), as_exp_bin_blob("device_flags")),

    as_exp_bytes(want, sizeof(want))));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags")),

    Exp.val(new byte[] {0x03})));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGet

exp = Eq(BitGet(16, 8, BlobBin("device_flags")), bytearray([0x03])).compile()
```

---

#### `bit_get_int`

```python
bit_get_int(bit_offset, bit_size, signed, bin)
```

Description: Returns the `bit_size` bits starting at `bit_offset` as an integer, read as signed when `signed` is true and as unsigned when it is false.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bit_offset` | `integer` | 
Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `signed` | `boolean literal` | 

Whether to read the region as a signed integer.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Filter where the signed 8-bit integer at bit offset `32` in `device_flags` equals `5` (fifth byte `0x05`).

-   [Java SDK](#tab-panel-1282)
-   [Python SDK](#tab-panel-1283)
-   [Rust](#tab-panel-1284)
-   [C#](#tab-panel-1285)
-   [Go](#tab-panel-1286)
-   [Node.js](#tab-panel-1287)
-   [C](#tab-panel-1288)
-   [Java](#tab-panel-1289)
-   [Python](#tab-panel-1290)

```java
String exp = "$.device_flags.bitGetInt(offset: 32, size: 8, signed: true) == 5";
```

```python
exp = "$.device_flags.bitGetInt(offset: 32, size: 8, signed: true) == 5"
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, eq, int_val};

let exp = eq(

    bit_exp::get_int(int_val(32), int_val(8), true, blob_bin("device_flags".into())),

    int_val(5));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.GetInt(Exp.Val(32), Exp.Val(8), true, Exp.BlobBin("device_flags")),

    Exp.Val(5)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitGetInt(as.ExpIntVal(32), as.ExpIntVal(8), true, as.ExpBlobBin("device_flags")),

  as.ExpIntVal(5),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.getInt(exp.binBlob('device_flags'), true, exp.int(8), exp.int(32)),

  exp.int(5),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get_int(as_exp_int(32), as_exp_int(8), true, as_exp_bin_blob("device_flags")),

    as_exp_int(5)));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.getInt(Exp.val(32), Exp.val(8), true, Exp.blobBin("device_flags")),

    Exp.val(5)));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitGetInt

exp = Eq(BitGetInt(32, 8, True, BlobBin("device_flags")), 5).compile()
```

---

#### `bit_lscan`

```python
bit_lscan(bit_offset, bit_size, value, bin)
```

Description: Returns the position of the first bit equal to `value`, scanning the `bit_size` bits at `bit_offset` from left to right. The position is relative to `bit_offset`, so 0 is the bit at `bit_offset` itself. Returns `-1` when no bit matches.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bit_offset` | `integer` | 
Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `boolean` | 

Bit value to look for: true finds a bit set to 1, false finds a bit set to 0.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Filter where a left scan for a set bit in the fifth byte of `device_flags` (bits 32–39) returns index `5`.

-   [Java SDK](#tab-panel-1291)
-   [Python SDK](#tab-panel-1292)
-   [Rust](#tab-panel-1293)
-   [C#](#tab-panel-1294)
-   [Go](#tab-panel-1295)
-   [Node.js](#tab-panel-1296)
-   [C](#tab-panel-1297)
-   [Java](#tab-panel-1298)
-   [Python](#tab-panel-1299)

```java
String exp = "$.device_flags.bitLscan(offset: 32, size: 8, value: true) == 5";
```

```python
exp = "$.device_flags.bitLscan(offset: 32, size: 8, value: true) == 5"
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, bool_val, eq, int_val};

let exp = eq(

    bit_exp::lscan(

        int_val(32),

        int_val(8),

        bool_val(true),

        blob_bin("device_flags".into())),

    int_val(5));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Lscan(Exp.Val(32), Exp.Val(8), Exp.Val(true), Exp.BlobBin("device_flags")),

    Exp.Val(5)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitLScan(as.ExpIntVal(32), as.ExpIntVal(8), as.ExpBoolVal(true), as.ExpBlobBin("device_flags")),

  as.ExpIntVal(5),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.lScan(exp.binBlob('device_flags'), exp.bool(true), exp.int(8), exp.int(32)),

  exp.int(5),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_lscan(

      as_exp_int(32), as_exp_int(8), as_exp_bool(true), as_exp_bin_blob("device_flags")),

    as_exp_int(5)));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.lscan(Exp.val(32), Exp.val(8), Exp.val(true), Exp.blobBin("device_flags")),

    Exp.val(5)));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitLeftScan

exp = Eq(BitLeftScan(32, 8, True, BlobBin("device_flags")), 5).compile()
```

---

#### `bit_rscan`

```python
bit_rscan(bit_offset, bit_size, value, bin)
```

Description: Returns the position of the last bit equal to `value`, scanning the `bit_size` bits at `bit_offset` from right to left. The position is relative to `bit_offset`. Returns `-1` when no bit matches.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bit_offset` | `integer` | 
Offset in bits from the start of the blob to the first bit of the region.

 |
| `bit_size` | `integer` | 

Width of the region in bits.

 |
| `value` | `boolean` | 

Bit value to look for: true finds a bit set to 1, false finds a bit set to 0.

 |
| `bin` | `blob` | 

Blob bin to operate on, or any expression that evaluates to a blob.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Filter where a right scan for a set bit in the fifth byte of `device_flags` returns index `7`.

-   [Java SDK](#tab-panel-1300)
-   [Python SDK](#tab-panel-1301)
-   [Rust](#tab-panel-1302)
-   [C#](#tab-panel-1303)
-   [Go](#tab-panel-1304)
-   [Node.js](#tab-panel-1305)
-   [C](#tab-panel-1306)
-   [Java](#tab-panel-1307)
-   [Python](#tab-panel-1308)

```java
String exp = "$.device_flags.bitRscan(offset: 32, size: 8, value: true) == 7";
```

```python
exp = "$.device_flags.bitRscan(offset: 32, size: 8, value: true) == 7"
```

```rust
use aerospike::expressions::bitwise as bit_exp;

use aerospike::expressions::{blob_bin, bool_val, eq, int_val};

let exp = eq(

    bit_exp::rscan(

        int_val(32),

        int_val(8),

        bool_val(true),

        blob_bin("device_flags".into())),

    int_val(7));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Rscan(Exp.Val(32), Exp.Val(8), Exp.Val(true), Exp.BlobBin("device_flags")),

    Exp.Val(7)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpBitRScan(as.ExpIntVal(32), as.ExpIntVal(8), as.ExpBoolVal(true), as.ExpBlobBin("device_flags")),

  as.ExpIntVal(7),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.bit.rScan(exp.binBlob('device_flags'), exp.bool(true), exp.int(8), exp.int(32)),

  exp.int(7),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_rscan(

      as_exp_int(32), as_exp_int(8), as_exp_bool(true), as_exp_bin_blob("device_flags")),

    as_exp_int(7)));
```

```java
import com.aerospike.client.exp.BitExp;

import com.aerospike.client.exp.Expression;

import com.aerospike.client.exp.Exp;

Expression exp = Exp.build(

  Exp.eq(

    BitExp.rscan(Exp.val(32), Exp.val(8), Exp.val(true), Exp.blobBin("device_flags")),

    Exp.val(7)));
```

```python
from aerospike_helpers.expressions import BlobBin, Eq

from aerospike_helpers.expressions.bitwise import BitRightScan

exp = Eq(BitRightScan(32, 8, True, BlobBin("device_flags")), 7).compile()
```

---