M508: Find One-Bits in a String

Author(s): M. Metcalf, R. Matthews Library: KERNLIB
Submitter: Submitted: 01.02.1982
Language: Fortran and CDC: COMPASS, IBM: Assembler Revised: 20.06.1985

BITPOS locates and counts the 1-bits in the right-most NBITS bits in a word or in a full-word array, returning their positions. Bit numbering is right-to-left, bit number 0 being the least significant bit in the first full word, bit number NBPW being the least significant bit in the second full word etc., where NBPW is the number of bits per machine word; this numbering is compatible with BITPAK (M441).

Structure:

SUBROUTINE subprogram
User Entry Names: BITPOS
External Entry Names: URKBYT (Fortran only)
COMMON Block Names and Lengths: /SLATE/ 40 (Fortran only)

Usage:

    CALL BITPOS(IWORDS,NBITS,IXV,NX)
IWORDS
Word or full-word array to be analysed.
NBITS
The first NBITS of array IWORDS are inspected.
IXV
Bit positions of the 1-bits in IWORD are placed into IXV(1) through IXV(NX) in increasing order. IXV must be dimensioned to NBITS at least. The positions are numbered from 0.
NX
Number of 1-bits found.

Notes:

The Fortran version contains a symbolic constant whose value must be set equal to the number of bits in a word (default 32).

Examples:

      DIMENSION IXV(9)
      IWORD = 1676
C     1676 in base 2 is 11010001100
      CALL BITPOS(IWORD,9,IXV,NX)
sets
      NX = 3, IXV(1) = 2, IXV(2) = 3, IXV(3) = 7.
tex2html_wrap_inline70

Michel Goossens Wed Jun 5 07:48:20 METDST 1996