Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.13 KB

shift.md

File metadata and controls

64 lines (42 loc) · 1.13 KB

shift

Shift the bits of each element left or right.

API

Numeric.bit.shift(value, places, right = false)

Moves bits left or right by the given count.

  • Parameters:
    • value: Scalar, vector, or matrix values to shift
    • places: Number of bit positions to shift
    • right: When true shifts bits toward the low end
  • Returns: Shifted values matching the input nesting shape
  • NumPy: Covers np.bitwise_left_shift, np.left_shift, np.bitwise_right_shift, np.right_shift through a single Numerix method.

Examples

Shift a vector to the left

import Numeric from '@neabyte/numerix'

const values = Numeric.bit.shift([1, 2], 1)

console.log(values)
// [2,4]

Shift a vector to the right

import Numeric from '@neabyte/numerix'

const values = Numeric.bit.shift([4, 2], 1, true)

console.log(values)
// [2,1]

Shift a single value

import Numeric from '@neabyte/numerix'

const value = Numeric.bit.shift(1, 3)

console.log(value)
// 8

Shift a matrix

import Numeric from '@neabyte/numerix'

const values = Numeric.bit.shift([[1, 2]], [1, 2])

console.log(values)
// [[2,8]]