bitops – Routines for low-level manipulation of binary data

Available on these boards
  • Adafruit Feather RP2040
  • Adafruit ItsyBitsy RP2040
  • Adafruit KB2040
  • Adafruit Macropad RP2040
  • Adafruit QT Py RP2040
  • Adafruit QT2040 Trinkey
  • Arduino Nano RP2040 Connect
  • Challenger NB RP2040 WiFi
  • Challenger RP2040 LTE
  • Challenger RP2040 LoRa
  • Challenger RP2040 WiFi
  • Cytron Maker Nano RP2040
  • Cytron Maker Pi RP2040
  • ELECFREAKS PICO:ED
  • Electrolama minik
  • EncoderPad RP2040
  • Fig Pi
  • Melopero Shake RP2040
  • Oak Dev Tech BREAD2040
  • Oak Dev Tech Cast-Away RP2040
  • Pimoroni Badger 2040
  • Pimoroni Interstate 75
  • Pimoroni Keybow 2040
  • Pimoroni Motor 2040
  • Pimoroni PGA2040
  • Pimoroni Pico LiPo (16MB)
  • Pimoroni Pico LiPo (4MB)
  • Pimoroni PicoSystem
  • Pimoroni Plasma 2040
  • Pimoroni Servo 2040
  • Pimoroni Tiny 2040 (2MB)
  • Pimoroni Tiny 2040 (8MB)
  • PyKey 18 Numpad
  • PyKey 44 Ergo
  • PyKey 60
  • PyKey 87 TKL
  • RP2.65-F
  • RP2040 Stamp
  • Raspberry Pi Pico
  • Seeeduino XIAO RP2040
  • Silicognition LLC RP2040-Shim
  • SparkFun MicroMod RP2040 Processor
  • SparkFun Pro Micro RP2040
  • SparkFun Thing Plus - RP2040
  • W5100S-EVB-Pico
  • W5500-EVB-Pico
  • Waveshare RP2040-Zero
  • WeAct Studio Pico
  • takayoshiotake Octave RP2040

bitops.bit_transpose(input: circuitpython_typing.ReadableBuffer, output: circuitpython_typing.WriteableBuffer, width: int = 8) circuitpython_typing.WriteableBuffer

“Transpose” a buffer by assembling each output byte with bits taken from each of width different input bytes.

This can be useful to convert a sequence of pixel values into a single stream of bytes suitable for sending via a parallel conversion method.

The number of bytes in the input buffer must be a multiple of the width, and the width can be any value from 2 to 8. If the width is fewer than 8, then the remaining (less significant) bits of the output are set to zero.

Let stride = len(input)//width. Then the first byte is made out of the most significant bits of [input[0], input[stride], input[2*stride], ...]. The second byte is made out of the second bits, and so on until the 8th output byte which is made of the first bits of input[1], input[1+stride, input[2*stride], ...].

The required output buffer size is len(input) * 8  // width.

Returns the output buffer.