bits and

For bits.

Performs bitwise and for ints or binary values.

Command Type

built-in

Signature

> bits and {flags} (target)

Flags

  • --endian, -e {string}: Byte encode endian, available options: native(default), little, big.

Parameters

  • target: Right-hand side of the operation.

Input/output types:

input output
int int
binary binary
list<int> list<int>
list<binary> list<binary>

Examples

Apply bitwise and to two numbers

> 2 | bits and 2
2

Apply bitwise and to two binary values

> 0x[ab cd] | bits and 0x[99 99]
Length: 2 (0x2) bytes | null_char printable whitespace ascii_other non_ascii
00000000:   89 89                                                ××

Apply bitwise and to a list of numbers

> [4 3 2] | bits and 2
╭───┬───╮
│ 0 │ 0 │
│ 1 │ 2 │
│ 2 │ 2 │
╰───┴───╯

Apply bitwise and to a list of binary data

> [0x[7f ff] 0x[ff f0]] | bits and 0x[99 99]
╭───┬────────────╮
│ 0 │ [25, 153]  │
│ 1 │ [153, 144] │
╰───┴────────────╯

Apply bitwise and to binary data of varying lengths with specified endianness

> 0x[c0 ff ee] | bits and 0x[ff] --endian big
Length: 3 (0x3) bytes | null_char printable whitespace ascii_other non_ascii
00000000:   00 00 ee                                             00×

Apply bitwise and to input binary data smaller than the operand

> 0x[ff] | bits and 0x[12 34 56] --endian little
Length: 3 (0x3) bytes | null_char printable whitespace ascii_other non_ascii
00000000:   12 00 00                                             •00

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.