shift ( x n -- y )
Factor documentation > Factor handbook > The language > Numbers > Arithmetic > Bitwise arithmetic
Prev:bitnot ( x -- y )
Next:2/ ( x -- y )


Vocabulary
math

Inputs and outputs
xan integer
nan integer
yan integer


Word description
Shifts x to the left by n bits if n is positive, or -n bits to the right if n is negative. A left shift of a fixnum may overflow, yielding a bignum. A right shift may result in bits “falling off” the right hand side and being discarded.

Examples
USING: math prettyprint ; 0b101 5 shift .b
10100000

USING: math prettyprint ; 0b11111 -2 shift .b
111


Definition
IN: math

GENERIC# shift 1 ( x n -- y ) foldable flushable


Methods
USING: math math.private ;

M: bignum shift integer>fixnum bignum-shift ; inline


USING: math math.private ;

M: fixnum shift integer>fixnum fixnum-shift ; inline