---
title: "Blob bin operations"
description: "Aerospike bitwise expression operations for blob bins, covering read/modify functions with multi-language examples."
---

# Blob bin operations

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

Aerospike blob (bytes) bins support bitwise read and modify operations inside [expressions](https://aerospike.com/docs/develop/expressions/) (filters, `operate` pipelines, and policies that accept expression filters). Use them to read bit ranges, count or scan bits, resize or patch bytes, and apply bitwise math without round-tripping the whole blob to the client.

Blob operations that read stored data evaluate to `unknown` when the underlying bin or key is missing, the type does not match, or the value is not yet available during the metadata-only phase of filter evaluation. See [Record storage](https://aerospike.com/docs/develop/expressions/storage) and the [expressions overview](https://aerospike.com/docs/develop/expressions/) execution model.

This reference lists each `bit_*` expression (for example `bit_get`, `bit_count`, `bit_set`, `bit_add`) with multi-language examples. For the underlying datatype and non-expression APIs, see [Blob (bytes)](https://aerospike.com/docs/develop/data-types/blob/).

Composing expressions

In each operation, the blob bin operand (`blob_bin_expr` in the argument tables) can be any blob-valued expression, not only `Exp.blobBin(...)`. The [`bit_set`](https://aerospike.com/docs/develop/expressions/blob-bin#bit_set) reference includes an example that uses `BitExp.get` on the result of `BitExp.set`—a read on a temporary blob after a modify. Many other modify (and some read) operations show similar composition: their examples nest another expression as the blob bin operand.

## Modify

#### `bit_add`

```python
bit_add(policy, bit_offset, bit_size, value, action_flags, bin)
```

Description: Invokes the [add](https://aerospike.com/develop/data-types/blob#add) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `integer_expr` |
| `action_flags` | `library_specific` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-865)
-   [Python](#tab-panel-866)
-   [C](#tab-panel-867)
-   [Go](#tab-panel-868)
-   [C#](#tab-panel-869)
-   [Node.js](#tab-panel-870)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

#### `bit_and`

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

Description: Invokes the [and](https://aerospike.com/develop/data-types/blob#and) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `blob_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

Introduced: 5.2.0.4

Example: Filter where AND-ing bits 16–23 with `0x01` leaves the first byte unchanged.

-   [Java](#tab-panel-871)
-   [Python](#tab-panel-872)
-   [C](#tab-panel-873)
-   [Go](#tab-panel-874)
-   [C#](#tab-panel-875)
-   [Node.js](#tab-panel-876)

```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.and(

          BitPolicy.Default,

          Exp.val(16),

          Exp.val(8),

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

          Exp.blobBin("device_flags"))),

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

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

from aerospike_helpers.expressions.bitwise import BitAnd, BitGet

b = BlobBin("device_flags")

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

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

as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_bit_get(

      as_exp_int(0),

      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_bit_get(as_exp_int(0), as_exp_int(8), as_exp_bin_blob("device_flags"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = as.ExpEq(

  as.ExpBitGet(

    as.ExpIntVal(0),

    as.ExpIntVal(8),

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

  ),

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

)
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    BitExp.Get(

      Exp.Val(0),

      Exp.Val(8),

      BitExp.And(

        BitPolicy.Default,

        Exp.Val(16),

        Exp.Val(8),

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

        Exp.BlobBin("device_flags"))),

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

```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(0)),

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

)
```

---

#### `bit_insert`

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

Description: Invokes the [insert](https://aerospike.com/develop/data-types/blob#insert) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bytes_offset` | `integer_expr` |
| `blob` | `blob_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-877)
-   [Python](#tab-panel-878)
-   [C](#tab-panel-879)
-   [Go](#tab-panel-880)
-   [C#](#tab-panel-881)
-   [Node.js](#tab-panel-882)

```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()
```

```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),

      0,

      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)));
```

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

_ = 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),

)
```

```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)));
```

```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),

)
```

---

#### `bit_lshift`

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

Description: Invokes the [lshift](https://aerospike.com/develop/data-types/blob#lshift) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `shift_bit_count` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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 (`TestBitExp` pattern).

-   [Java](#tab-panel-883)
-   [Python](#tab-panel-884)
-   [C](#tab-panel-885)
-   [Go](#tab-panel-886)
-   [C#](#tab-panel-887)
-   [Node.js](#tab-panel-888)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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(6), exp.int(0)), exp.int(6), exp.int(0)),

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

)
```

---

#### `bit_not`

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

Description: Invokes the [not](https://aerospike.com/develop/data-types/blob#not) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

Introduced: 5.2.0.4

Example: Filter where NOT-ing one bit at offset `6` makes the first byte match the original second byte (`0x42`).

-   [Java](#tab-panel-889)
-   [Python](#tab-panel-890)
-   [C](#tab-panel-891)
-   [Go](#tab-panel-892)
-   [C#](#tab-panel-893)
-   [Node.js](#tab-panel-894)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

#### `bit_or`

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

Description: Invokes the [or](https://aerospike.com/develop/data-types/blob#or) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `blob_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-895)
-   [Python](#tab-panel-896)
-   [C](#tab-panel-897)
-   [Go](#tab-panel-898)
-   [C#](#tab-panel-899)
-   [Node.js](#tab-panel-900)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

#### `bit_remove`

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

Description: Invokes the [remove](https://aerospike.com/develop/data-types/blob#remove) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bytes_offset` | `integer_expr` |
| `byte_size` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-901)
-   [Python](#tab-panel-902)
-   [C](#tab-panel-903)
-   [Go](#tab-panel-904)
-   [C#](#tab-panel-905)
-   [Node.js](#tab-panel-906)

```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()
```

```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)));
```

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

_ = 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),

)
```

```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)));
```

```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),

)
```

---

#### `bit_resize`

```python
bit_resize(policy, bytes_size, flags, bin)
```

Description: Invokes the [resize](https://aerospike.com/develop/data-types/blob#resize) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bytes_size` | `integer_expr` |
| `flags` | `library_specific` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-907)
-   [Python](#tab-panel-908)
-   [C](#tab-panel-909)
-   [Go](#tab-panel-910)
-   [C#](#tab-panel-911)
-   [Node.js](#tab-panel-912)

```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()
```

```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))));
```

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

_ = 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}),

)
```

```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})));
```

```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])),

)
```

---

#### `bit_rshift`

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

Description: Invokes the [rshift](https://aerospike.com/develop/data-types/blob#rshift) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `shift_bit_count` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-913)
-   [Python](#tab-panel-914)
-   [C](#tab-panel-915)
-   [Go](#tab-panel-916)
-   [C#](#tab-panel-917)
-   [Node.js](#tab-panel-918)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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(6), exp.int(24)), exp.int(6), exp.int(26)),

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

)
```

---

#### `bit_set`

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

Description: Invokes the [set](https://aerospike.com/develop/data-types/blob#set) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `blob_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-919)
-   [Python](#tab-panel-920)
-   [C](#tab-panel-921)
-   [Go](#tab-panel-922)
-   [C#](#tab-panel-923)
-   [Node.js](#tab-panel-924)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

#### `bit_set_int`

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

Description: Invokes the [set\_integer](https://aerospike.com/docs/develop/data-types/blob#set_int) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-925)
-   [Python](#tab-panel-926)
-   [C](#tab-panel-927)
-   [Go](#tab-panel-928)
-   [C#](#tab-panel-929)
-   [Node.js](#tab-panel-930)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

#### `bit_subtract`

```python
bit_subtract(policy, bit_offset, bit_size, value, action_flags, bin)
```

Description: Invokes the [subtract](https://aerospike.com/develop/data-types/blob#subtract) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `integer_expr` |
| `action_flags` | `library_specific` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-931)
-   [Python](#tab-panel-932)
-   [C](#tab-panel-933)
-   [Go](#tab-panel-934)
-   [C#](#tab-panel-935)
-   [Node.js](#tab-panel-936)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

#### `bit_xor`

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

Description: Invokes the [xor](https://aerospike.com/develop/data-types/blob#xor) operation.

Arguments: | Name | Type |
| --- | --- |
| `policy` | `library_specific` |
| `bit_offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `blob_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

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](#tab-panel-943)
-   [Python](#tab-panel-944)
-   [C](#tab-panel-945)
-   [Go](#tab-panel-946)
-   [C#](#tab-panel-947)
-   [Node.js](#tab-panel-948)

```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()
```

```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"))));
```

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

bin := as.ExpBlobBin("device_flags")

_ = 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),

)
```

```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"))));
```

```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)),

)
```

---

## Read

#### `bit_count`

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

Description: Invokes the [count](https://aerospike.com/develop/data-types/blob#count) operation.

Arguments: | Name | Type |
| --- | --- |
| `offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `integer_bin`

Introduced: 5.2.0.4

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

-   [Java](#tab-panel-937)
-   [Python](#tab-panel-938)
-   [C](#tab-panel-939)
-   [Go](#tab-panel-940)
-   [C#](#tab-panel-941)
-   [Node.js](#tab-panel-942)

```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()
```

```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)));
```

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

_ = as.ExpGreater(

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

  as.ExpIntVal(1),

)
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(BitExp.Count(Exp.Val(8), Exp.Val(8), Exp.BlobBin("device_flags")), Exp.Val(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),

)
```

---

#### `bit_get`

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

Description: Invokes the [get](https://aerospike.com/develop/data-types/blob#get) operation.

Arguments: | Name | Type |
| --- | --- |
| `offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `bin` | `blob_bin_expr` |

Returns: `blob_bin`

Introduced: 5.2.0.4

Example: Filter where bits 16–23 of blob bin `device_flags` read as one byte equal `0x03` (example layout matches Aerospike client `TestBitExp` five-byte pattern `01 42 03 04 05`).

-   [Java](#tab-panel-949)
-   [Python](#tab-panel-950)
-   [C](#tab-panel-951)
-   [Go](#tab-panel-952)
-   [C#](#tab-panel-953)
-   [Node.js](#tab-panel-954)

```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()
```

```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))));
```

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

_ = as.ExpEq(

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

  as.ExpBlobVal([]byte{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})));
```

```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])),

)
```

---

#### `bit_get_int`

```python
bit_get_int(offset, bit_size, is_signed, bin)
```

Description: Invokes the [get\_integer](https://aerospike.com/develop/data-types/blob#get_integer) operation.

Arguments: | Name | Type |
| --- | --- |
| `offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `is_signed` | `boolean_value` |
| `bin` | `blob_bin_expr` |

Returns: `integer_bin`

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` in the `TestBitExp` pattern).

-   [Java](#tab-panel-955)
-   [Python](#tab-panel-956)
-   [C](#tab-panel-957)
-   [Go](#tab-panel-958)
-   [C#](#tab-panel-959)
-   [Node.js](#tab-panel-960)

```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()
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

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

    as_exp_int(5)));
```

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

_ = as.ExpEq(

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

  as.ExpIntVal(5),

)
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

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

    Exp.Val(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),

)
```

---

#### `bit_lscan`

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

Description: Invokes the [lscan](https://aerospike.com/develop/data-types/blob#lscan) operation.

Arguments: | Name | Type |
| --- | --- |
| `offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `boolean_expr` |
| `bin` | `blob_bin_expr` |

Returns: `integer_bin`

Introduced: 5.2.0.4

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

-   [Java](#tab-panel-961)
-   [Python](#tab-panel-962)
-   [C](#tab-panel-963)
-   [Go](#tab-panel-964)
-   [C#](#tab-panel-965)
-   [Node.js](#tab-panel-966)

```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()
```

```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)));
```

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

_ = as.ExpEq(

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

  as.ExpIntVal(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)));
```

```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),

)
```

---

#### `bit_rscan`

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

Description: Invokes the [rscan](https://aerospike.com/develop/data-types/blob#rscan) operation.

Arguments: | Name | Type |
| --- | --- |
| `offset` | `integer_expr` |
| `bit_size` | `integer_expr` |
| `value` | `boolean_expr` |
| `bin` | `blob_bin_expr` |

Returns: `integer_bin`

Introduced: 5.2.0.4

Example: Filter where a right scan for a set bit in the fourth byte of `device_flags` returns index `7` (`TestBitExp` pattern).

-   [Java](#tab-panel-967)
-   [Python](#tab-panel-968)
-   [C](#tab-panel-969)
-   [Go](#tab-panel-970)
-   [C#](#tab-panel-971)
-   [Node.js](#tab-panel-972)

```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()
```

```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)));
```

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

_ = as.ExpEq(

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

  as.ExpIntVal(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)));
```

```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),

)
```

---