# octetstring

The keyword octetstring denotes a basic string type whose distinguished values are the ordered sequences of 2n hexadecimal digits where n is a non-negative integer.

- octet string values are written between single quotes and followed by the capital letter O. (' 'O).
- A octet 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 octet 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 octet may be accessed using an array-like syntax. The leftmost octet has the index zero.
- The octet string may be empty.
- The length of the octet string can be constrained using the keyword length.
- Another way to limit the permitted values of an octet string is to list them.
- Predefined functions operating on octet strings:

- oct2hex converts an octet string value to a hexadecimal string.
- oct2int converts an octet string to the equivalent integer.
- oct2bit converts an octet string to a binary string.
- oct2str displays an octet string as a character string.
- oct2unichar converts an octet string as an universal character string.
- unichar2oct converts an universal charcter string to an octet string.
- lengthof returns an integer value indicating the number of octets in a string.
- get_stringencoding identifies the encoding of an octet string.
- remove_bom strips the BOM if it is present or returns the original octet string.

TITAN specific extension to the standard: oct2char converts an octet string to a character string.

Related keywords:

- bit2oct
- char2oct
- hex2oct
- int2oct
- length
- lengthof
- oct2bit
- oct2char
- oct2hex
- oct2int
- oct2unichar
- unichar2oct
- oct2str
- get_stringencoding
- remove_bom
- str2oct
- substr
- and4bit
- not4bit
- or4bit
- xor4bit

### octetstring

Example 1:

const octetstring c_ok := 'A5'O;

The constant defined is called c_ok and contains the octet string A5.

Example 2:

const octetstring c_entier := int2oct (266,2);

The constant c_entier will contain the octet string 010A because the converted integer number (127 -> 10A) must be coded on 2 octets and therefore padded with a leading zero.

Example 3:

const boolean c_niet := ( c_entier == c_ok );

The constant c_niet will have the value false, because two octet strings are not equal. The parentheses are optional.

Example 4:

const octetstring c_clotre := c_entier & c_ok;

The constant c_clotre will contain the octet string 010AA5

Example 5:

const octetstring c_samotny := c_entier[1];

The constant called c_samotny will contain the octet string 0A.

Example 6:

const octetstring c_nil := ''O;

The constant called c_nil will be an empty string.

Example 7a:

const hexstring c_kungsen := oct2hex ('AA'O);

The constant called c_kungsen will have the hexadecimal value AA. Although both values on the screen may look the same (AA), they have different types (octet string respective character string).

Example 7b:

const integer c_prednost := oct2int ('55'O);

The constant called c_prednost will have the integer value 85. The result will be always positive.

Example 7c:

const bitstring c_kvar := oct2bit ('44'O);

The constant called c_kvar will contain the bit string 01000100.

Example 7d:

const charstring c_lettres := oct2str ('80FBBC0530A0'O);

The constant called c_lettres will contain the string 80FBBC0530A0 because the resulting character string has the double length as the octet string and contains only the characters '0' .. 'F'.

Example 7e:

const integer c_laenge := lengthof ('80FBBC0530A0'O);

The constant called c_laenge will have the value 6 corresponding to the number of octets in the string .

Example 7f:

const charstring c_specific := oct2char (â4469707379âO);

The constant called c_specific will contain the string "Dipsy" because the resulting character string will have the same length as the incoming octet string. The octets are interpreted as ISO/IEC 646 [8] codes (according to the IRV) and the resulting characters are stored in the returned string. Octet values higher than 7F cause an error.

Example 8:

var octetstring c_hinder ('1010'O,'77'O,'AA55CC'O );

The variable called c_hinder may hold the octet strings 1010, 77 and AA55CC only.

Example 9:

const octetstring c_go_round := '1122334455'O <@ (1+2);

The constant called c_go_round will hold the value '4455112233'O (the left operand rotated by three octets).

Example 10:

const octetstring c_slip := '1122334455'O << (1+1);

The constant called c_slip will hold the value '3344550000'O (the left operand shifted by two octets) .

BNF definition of octetstring
BNF definition of octetstring value