# cpct_get2Bits

Returns the value of a given group of 2 bits into an array (0, 1, 2 or 3)

#### C Definition

u8 cpct_get2Bits (void* array, u16 index);

#### Input Parameters (4 Bytes)

(2B DE) array | Pointer to the first byte of the array
(2B HL) index | Position of the group of 2 bits to be retrieved from the array

#### Assembly call (Input parameters on registers)

>     call cpct_get2Bits_asm

#### Parameter Restrictions

- array must be the memory location of the first byte of the array. However, this function will accept any given 16-value, without performing any check. So, be warned that giving mistaken values to this function will not make it fail, but giving an unpredictable return result.
- index position of the group of 2 bits to be retrieved from the array, starting in 0. As this function does not perform any boundary check, if you gave an index outside the boundaries of the array, the return result would be unpredictable and meaningless.

#### Return value

u8 | Value of the selected group of 2 bits: 0, 1, 2 or 3

#### Known limitations

- Maximum of 65536 groups of 2-bits, 16384 bytes per array.

#### Details

Returns 0, 1, 2 or 3 depending on the value of the 2-bits group at the given position (index) in the specified array. It will assume that the array elements have a size of 8 bits and also that the given position is not bigger than the number of bits in the array (size of the array multiplied by 4).

#### Destroyed Register values

AF, DE, HL

#### Required memory

C-binding | 38 bytes
ASM-binding | 35 bytes

#### Time Measures

>     Case       | Microsecs | CPU Cycles
>     -----------------------------------
>     Best (3)   |    41     |   164
>     -----------------------------------
>     Worst (1)  |    47     |   188
>     -----------------------------------
>     ASM-saving |   -12     |   -48
>     -----------------------------------

Start of the function code (without bindings for calling)

unsigned char (u8 = unsigned 8-bits, 1 byte )
Returns the value of a given group of 2 bits into an array (0, 1, 2 or 3)
unsigned int (u16 = unsigned 16-bits, 2 bytes)
Close