Node:Logical Number Operations, Next:, Previous:Quantities, Up:Extensions



Logical Number Operations

These functions operate on the 2's complement binary representation of an exact integer.

logand i ... Function
Returns the bit-wise logical "and" of the arguments. If no argument is given, the result is -1.

logior i ... Function
Returns the bit-wise logical "(inclusive) or" of the arguments. If no argument is given, the result is 0.

logxor i ... Function
Returns the bit-wise logical "exclusive or" of the arguments. If no argument is given, the result is 0.

lognot i Function
Returns the bit-wise logical inverse of the argument.

logop op x y Function
Perform one of the 16 bitwise operations of x and y, depending on op.

bittest i j Function
Returns true if the arguments have any bits in common. Same as (not (zero? (logand i j))), but is more efficient.

logbit? i pos Function
Returns #t iff the bit numbered pos in i is one.

arithmetic-shift i j Function
Shifts i by j. It is a "left" shift if j>0, and a "right" shift if j<0.

The result is equal to (floor (* i (expt 2 j))).

ash i j Function
Alias for arithmetic-shift.

logcount i Function
Count the number of 1-bits in i, if it is non-negative. If i is negative, count number of 0-bits.

integer-length i Function
Return number of bits needed to represent i in an unsigned field. Regardless of the sign of i, return one less than the number of bits needed for a field that can represent i as a two's complement integer.

bit-extract n start end Function
Return the integer formed from the (unsigned) bit-field starting at start and ending just before end. Same as (arithmetic-shift (bitand n (bitnot (arithmetic-shift -1 end))) (- start)).