Dan Nagle's Technical Site

Module bit_functions

Home --> Fact Sheet --> Free Source Code --> bit_functions

About the Module bit_functions

Go directly to Downloads

The module bit_functions contains some functions which operate on variables of type integer at the bit level. Included are functions to merge bits, count bits, masks and shifts. This module uses module standard_types, which may be obtained from the Portability Project pages. The source code requires use of the coco preprocessor to select code for the integer kinds supported by your processor. The operators and functions are provided for all integer kinds.

Back to the Top

A list of (most) constants and procedures defined follows.

.not. is a unary bitwise operator, synonymous with not().
.and., .or., .eor. are binary bitwise operators, synonymous with iand(), ior(), ieor(), respectively.
.eqv., .neqv., .xor., are binary bitwise operators.
.hamd. is a binary bitwise operator, which provides the Hamming distance calculation (number of bits set to 1 in the .eor. of the operands).
.shift. and .rotate. are binary linear and circular shift operators.

Back to the Top

csmg() is a conditional scalar merge.
compl() is synonymous with not().
leadz() returns the leading (leftmost) zeros count.
lastz() returns the trailing (rightmost) zeros count.
popcnt() returns the population count (number of bits set to 1).
poppar() returns the parity of the population count.
maskl() and maskr() return masks from the left or the right, respectively.
mask() returns a mask from either the left or the right.
ilen() returns the number of bits needed to express its argument (a la HPF).
hamd() provides the Hamming distance between its arguments.
dshftl() and dshftr() are double right anf left shifts, respectively.
dshftc() is a double circular shift.

Back to the Top


To download the bit_functions module, click bit_functions. This module depends on the standard_types module, see the portability project for information about how to make one for your compiler. This module also requires the use of the coco preprocessor to compile code for the kinds supported by various processors.

Back to the Top

To make comments or suggestions regarding standard_functions, or any of our software, please E-mail me. We're always happy to share the experiences others have using our software.

Home - Fact Sheet - Free Source Code - Fortran Links - Email me

Back to the Top