Next: , Previous: , Up: Numbers   [Contents][Index]


5.4.9 Bitwise Functions

These functions operate on the bit string which an integer represents, assuming a two’s complement representation.

Function: lsh number count

This function shifts the integer number count bits to the left, if count is negative number is shifted to the right instead.

(lsh 1 8)
    ⇒ 256

(lsh 256 -8)
    ⇒ 1
Function: logand number1 #!rest numbers

This function uses a bit-wise logical ‘and’ operation to combine all its arguments (there must be at least one argument).

(logand 15 8)
    ⇒ 8

(logand 15 7 20)
    ⇒ 4
Function: logior number1 #!rest numbers

Uses a bit-wise logical ‘inclusive-or’ to combine all its arguments (there must always be at least one argument).

(logior 1 2 4)
    ⇒ 7
Function: logxor number1 #!rest numbers

Uses a bitwise logical ‘exclusive-or’ to combine all its arguments (there must be at least one).

(logxor 7 3)
    ⇒ 4
Function: lognot number

This function inverts all the bits in number.

(lognot 0)
    ⇒ -1

(lognot 2)
    ⇒ -3

(lognot -1)
    ⇒ 0