Bits

  • bits — Various commands for working with bits.
  • bits and — Performs bitwise and for ints or binary values.
  • bits not — Performs logical negation on each bit.
  • bits or — Performs bitwise or for ints or binary values.
  • bits rol — Bitwise rotate left for ints or binary values.
  • bits ror — Bitwise rotate right for ints or binary values.
  • bits shl — Bitwise shift left for ints or binary values.
  • bits shr — Bitwise shift right for ints or binary values.
  • bits xor — Performs bitwise xor for ints or binary values.

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

Tips

Intro

bits and keeps the bits set in both numbers.

2 | bits and 3

bits shl shifts bits to the left.

1 | bits shl 3

Basic

or, then and, combines two bit checks.

2 | bits or 1 | bits and 3

Shift left, then take abs.

1 | bits shl 2 | math abs

Intermediate

Shift left, shift right, then abs.

1 | bits shl 3 | bits shr 1 | math abs

Shift each number inside a closure.

[1 2 3] | each {|n| $n | bits shl 1} | math sum

Advanced

Four bit and text steps.

1 | bits shl 4 | bits shr 1 | into string | str length