Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.02 KB

pack.md

File metadata and controls

64 lines (42 loc) · 1.02 KB

pack

Pack bit values into bytes.

API

Numeric.bit.pack(values, order, level)

Groups bits into bytes using the requested order.

  • Parameters:
    • values: Bit values to pack
    • order: Byte order used for packing
    • level: Optional axis along which to pack two-dimensional matrices
  • Returns: Packed byte values
  • NumPy: Equivalent to np.packbits.

Examples

Pack eight bits into one byte

import Numeric from '@neabyte/numerix'

const bytes = Numeric.bit.pack([1, 0, 1, 0, 0, 0, 0, 1])

console.log(bytes)
// [161]

Pack bits in little endian order

import Numeric from '@neabyte/numerix'

const bytes = Numeric.bit.pack([1, 0, 1, 0, 0, 0, 0, 1], 'little')

console.log(bytes)
// [133]

Pack fewer than eight bits

import Numeric from '@neabyte/numerix'

const bytes = Numeric.bit.pack([1, 0, 1])

console.log(bytes)
// [160]

Pack an empty bit vector

import Numeric from '@neabyte/numerix'

const bytes = Numeric.bit.pack([])

console.log(bytes)
// []