David
Farruggio

MathGenie

bitshift

Shift bits specified number of places

Syntax and Description

bitshift(A,k) returns A shifted to the left by k bits, equivalent to multiplying by 2^k. Negative values of k correspond to shifting bits right or dividing by 2^|k| and rounding to the nearest integer towards negative infinity. Any overflow bits are truncated.
  • If A is an array of signed integers, then bitshift returns the arithmetic shift results, preserving the signed bit when k is negative, and not preserving the signed bit when k is positive.
  • If k is positive, bitshift shifts the bits to the left and inserts k 0-bits on the right.
  • If k is negative and A is nonnegative, then bitshift shifts the bits to the right and inserts |k| 0-bits on the left.
  • If k is negative and A is negative, then bitshift shifts the bits to the right and inserts |k| 1-bits on the left.
bitshift(A,k,assumedtype) assumes that A is are of assumedtype. Assumed types are:
  • 1 = uint64
  • 2 = uint32
  • 3 = uint16
  • 4 = uint8
  • 5 = int64
  • 6 = int32
  • 7 = int16
  • 8 = int8

Back to functions