www.delorie.com/gnu/docs/kawa/kawa_35.html search
Kawa, the Java-based Scheme system

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

## 7.7 Logical Number Operations

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

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

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

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

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

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

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

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

Function: arithmetic-shift i j
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)))`.

Function: ash i j
Alias for `arithmetic-shift`.

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

Function: integer-length i
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.

Function: bit-extract n start end
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))`.

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

 webmaster delorie software   privacy Copyright © 2003   by The Free Software Foundation Updated Jun 2003