next up previous index
Next: M507 Occupied Length Up: CERNLIB Previous: M502 Decoding Options

M503 Locate the One-Bits of a Word or an Array

Routine ID: M503
Author(s): M. Metcalf, R. MatthewsLibrary: KERNLIB
Submitter: Submitted: 01.02.1982
Language: Fortran or AssemblerRevised: 20.06.1985

UBITS locates and counts the 1-bits in the right-most NBITS bits in a word or full-word array, returning their positions. Bit numbering is right to left, bit number 1 being the least significant bit in the first full word, bit number NBPW+1 being the least significant bit in the second full word, where NBPW is the number of bits per machine word.

Structure:

SUBROUTINE subprogram
User Entry Names: UBITS
External References: UPKBYT (M422) (Fortran version only)

Usage:

    CALL UBITS(IWORDS,NBITS,IXV,NX)
IWORDS
Word or full-word array to be analysed.
NBITS
Bits 1 to 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.
NX
Number of 1-bits found.

Examples:

     DIMENSION IXV(9)
     IWORD=1676
C    1676 in base 2 is 11010001100
     CALL UBITS(IWORD,9,IXV,NX)
sets
   NX = 3, IXV(1) = 3, IXV(2) = 4, IXV(3) = 8.

M507


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995