# bitstring

The keyword bitstring denotes a basic string type whose distinguished values are the ordered sequences of zero, one or more bits.

- Bit string values are written between single quotes and followed by the capital letter B. (' 'B).
- A bit string may be specified by its integer value using a conversion function.
- The relational operators equality (==) and non-equality (!=) can be used to compare values of two bit strings
- The shift operators perform the shift left (<<) and shift right (>>) operations.
- The rotate operators perform the rotate left (<@) and rotate right (@>) operations.
- The concatenation operator (&) performs a simple concatenation from left to right.
- Bitwise operators (and4b, not4b, or4b, xor4b) are used to manipulate bits in the string.
- A single bit may be accessed using an array-like syntax. The leftmost bit has the index zero.
- The bit string may be empty.
- Predefined functions operating on bit strings:

- bit2hex converts a bit string value to a hexadecimal string.
- bit2int converts a bit string to the equivalent integer.
- bit2oct converts a bit string to an octet string.
- bit2str converts a bit string to a character string.
- lengthof returns an integer value indicating the number of bits in a string.

- The length of the bit string can be constrained using the keyword length.
- Another way to limit the permitted values of a bit string is to list them.

Related keywords:

- bit2hex
- bit2int
- bit2oct
- bit2str
- hex2bit
- int2bit
- length
- lengthof
- oct2bit
- str2bit
- substr
- and4bit
- not4bit
- or4bit
- xor4bit

### bitstring

Example 1:

const bitstring c_bitfolyam := '01001'B;

The constant defined is called c_bitfolyam and has the binary value 01001.

Example 2:

const bitstring c_whole := int2bit (112,8);

The constant called c_whole will contain the string 01110000 because the converted integer number (112 -> 1110000) must be coded on 8 bits and therefore padded with a leading zero.

Example 3:

const boolean c_vrai := ( c_bitfolyam != c_whole );

The constant c_vrai will have the value true, because two bit strings are not equal. The parentheses are optional.

Example 4:

const bitstring c_stick := c_bitfolyam & c_whole;

The constant c_stick will have the binary value 0100101110000.

Example 5:

const bitstring c_jediny := c_bitfolyam[1];

The constant called c_jediny will have the binary value 1.

Example 6:

const bitstring c_inget := ''B;

The constant called c_inget will be an empty string.

Example 7a:

const hexstring c_ganz := bit2hex ('111010111'B);

The constant called c_ganz will have the hexadecimal value 1D7. The bit string is divided in groups of four starting from the right and converted to hexadecimal digits. When the last group has less than four bits it will be padded with leading zeros

Example 7b:

const integer c_samostatny := bit2int ('1111111'B);

The constant called c_samostatny will have the integer value 127. The result will be always positive.

Example 7c:

const octetstring c_tre := bit2oct ('101001011010'B);

The constant called c_tre will have the value '0A5A'O .

Example 7d:

const charstring c_bokstaever := bit2str ('101001011010'B);

The constant called c_bokstaever will contain the string 101001011010 because the resulting character string has the same length as the bit string and contains only the characters '0' and '1'.

Example 7e:

const integer c_longeur := lengthof ('01001011010'B);

The constant called c_longeur will have the value 11 corresponding to the number of bits in the string .

Example 8:

var bitstring c_zabradli ('1010'B,'11'B,'011'B );

The variable called c_zabradli may assume the binary values 1010, 11, 011 only.

Example 9:

const bitstring c_bithinta := '100001'B @> 2;

The constant called c_bithinta will hold the value '011000'B (the left operand rotated by two bits).

Example 10:

const bitstring c_slippery := '111001'B << 2;

The constant called c_slippery will hold the value ''100100'B (the left operand shifted by two bits).

BNF definition of bitstring
BNF definition of bitstring value