**Kawa, the Java-based Scheme system**

## 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))`

.