Scheme Programmer's Manual
NAME
bitwisebitcount  population count
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(bitwisebitcount ei)
(fxbitcount fx)
DESCRIPTION
If the argument is nonnegative, this procedure returns the number
of 1 bits in its two's complement representation.
Otherwise it returns the result of the following computation:
(bitwisenot (bitwisebitcount (bitwisenot ei)))
RETURN VALUES
Returns a single exact integer object.
EXAMPLES
(bitwisebitcount #b1)
=> 1
(bitwisebitcount #b1000)
=> 1
(bitwisebitcount #b1001)
=> 2
(bitwisebitcount #b1001)
=> 2
APPLICATION USAGE
This procedure is used to compute the Hamming distance. It's also used
in Hash Array Mapped Tries and other applications.
COMPATIBILITY
This procedure is new in R6RS. SRFI151 has the similar
procedure
bitcount.
ERRORS
This procedure can raise exceptions with the following condition types:
 &assertion (R6RS)

The wrong number of arguments was passed or an argument was outside its domain.
For
fxbitcount
the argument must be a fixnum.
SEE ALSO
bitwisefirstbitset(3scheme),
bitwiselength(3scheme)
STANDARDS
R6RS
HISTORY
This procedure can be implemented with the
popcount
procedure in x8664 processors. This instruction appeared even in some
early computers like the IBM Stretch (1961).
AUTHORS
This page is part of the
schememanpages
project.
It includes materials from the RnRS documents.
More information can be found at
Index
 NAME

 LIBRARY

 SYNOPSIS

 DESCRIPTION

 RETURN VALUES

 EXAMPLES

 APPLICATION USAGE

 COMPATIBILITY

 ERRORS

 SEE ALSO

 STANDARDS

 HISTORY

 AUTHORS

Return to Main Contents