1. Home
  2. BPCONVERT procedure

BPCONVERT procedure

Converts bit patterns between integers, pointers of set bits and textual descriptions (R.W. Payne).

Options

PRINT = string token Controls printed output (description); default desc
BITS = text, variate or pointer Labels for the individual bits; default !(1...31)
SEPARATOR = string Separator between the bit labels in the description; default '.'

Parameters

DATA = scalars, texts or pointers Bit patterns to convert
BP = scalars Bit patterns as integers
CONTENTS = pointers Bits that are set in each bit pattern
DESCRIPTION = text Textual description of each bit pattern

Description

Bit patterns are used by Genstat, and many other programs, to represent sets of objects like, for example, the factors and variates in a model term. Internally, they are stored in integers with a bit (i.e. a digit in the binary representation of the integer) for each object. The bit is set to one if the bit pattern contains the object, and zero otherwise. The contents of the bit patterns are then determined by logical AND operations, but this is not easy or convenient for implementers when debugging a program. BPCONVERT is therefore provided to enable a bit pattern to be converted between different representations: an integer (as above), a pointer with an element for each of the bits that is set in the bit pattern, a text containing the string (e.g. blocks.plots) that would represent the bit pattern in output.

The DATA parameter supplies the bit pattern to convert, in any of the three representations. The BP parameter can save it as an integer (in a scalar). The CONTENTS parameter can save it in a pointer. The DESCRIPTION parameter can save the textual description (in a text).

The BITS option provides the information to label the bits in CONTENTS and DESCRIPTION. This can be textual labels (in a text), numbers (in a variate) or identifiers of data structures (in a pointer); the default is to use the integers 1-31. The SEPARATOR option specifies the separator to use between the labels in descriptions; by default this is a dot.

 

Options: PRINT, BITS, SEPARATOR.
Parameters: DATA, BP, CONTENTS, DESCRIPTION.

See also

Procedure: NCONVERT.
Commands for: Calculations and manipulation.

Example

CAPTION   'BPCONVERT example'; STYLE=meta
BPCONVERT [BITS=!P(A,B,C,D,E,F,G,H)] 170; CONTENTS=Factors
PRINT     Factors
Updated on February 4, 2022

Was this article helpful?