# bit2hex

This function converts a single bitstring value to a single hexstring. The resulting hexstring represents the same value as the bitstring.

For the purpose of this conversion, a bitstring should be converted into a hexstring, where the bitstring is divided into groups of four bits beginning with the rightmost bit. Each group of four bits is converted into a hex digit as follows:

'0000'B -> '0'H, '0001'B -> '1'H, '0010'B -> '2'H, '0011'B -> '3'H, '0100'B -> '4'H, '0101'B -> '5'H,

'0110'B -> '6'H, '0111'B -> '7'H, '1000'B -> '8'H, '1001'B -> '9'H, '1010'B -> 'A'H, '1011'B -> 'B'H,

'1100'B -> 'C'H, '1101'B -> 'D'H, '1110'B ->'E'H, and '1111'B -> 'F'H.

When the leftmost group of bits does contain less than 4 bits, this group is filled with '0'B from the left until it contains exactly 4 bits and is converted afterwards. The consecutive order of hex digits in the resulting hexstring is the same as the order of groups of 4 bits in the bitstring.

Related keyword:

- bitstring
- hexstring

### bit2hex(bitstring value) return hexstring

Example 1:

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.