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

6.2.6 Bitwise operations

These procedures treat integers as half-open bit vectors. If an integer is positive, it is regarded as if infinite number of zeros are padded to the left. If an integer is negative, it is regarded in 2's complement form, and infinite number of 1's are padded to the left.

The API is consisntent to SLIB's "logical" module.

Function: ash n count
Shifts integer n left with count bits. If count is negative, ash shifts n right with -count bits.

 
; Note: 6  == [...00110], and
;       -6 == [...11010]
(ash 6 2)   => 24  ;[...0011000]
(ash 6 -2)  => 1   ;[...0000001]
(ash -6 2)  => -24 ;[...1101000]
(ash -6 -2) => -2  ;[...1111110]

Function: logand n1 n2 ...
Function: logior n1 n2 ...
Function: logxor n1 n2 ...
Returns bitwise and, bitwise inclusive or and bitwise exclusive or of two or more integers n1, n2 ....

Function: lognot n
Returns bitwise not of an integer n.

Function: logtest n1 n2 ...
== (not (zero? (logand n1 n2 ...)))

Function: logbit? index n
Returns #t if index-th bit of integer n is 1, #f otherwise.

Function: bit-field n start end
Extracts (start+1)-th bit to end-th bit (inclusive) from an exact integer n, where start < end.

Function: copy-bit index n bit
If bit is true, sets index-th bit of an exact integer n. If bit is false, resets index-th bit of an exact integer n.

Function: copy-bit-field n start end from

Function: logcount n

Function: integer-length n


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

This document was generated by Ken Dickey on November, 28 2002 using texi2html