# Bit Functions

GPC allows you to manipulate the bits of a given variable. Bit operations are quite complicated, however, there is not really much call for them in the GPC environment and most users will never need them. Therefore, this section will assume you have an understanding of bits, bit masks, how they correlate with bytes and the binary system.

Function | Description | Zen | Plus |

Sets one Bit | ✔️ | ✔️ | |

Clears one Bit | ✔️ | ✔️ | |

Tests a Bit | ✔️ | ✔️ | |

Stores a value into a Bit Index | ✔️ | ✔️ | |

Gets a value from the Bit Index | ✔️ | ✔️ |

## set_bit

`set_bit`

sets one bit of a variable based on its bit index

#### 🔴 **Syntax**

**Syntax**

`set_bit ( <variable> , <bit_index> );`

#### ⚪ **Parameters**

**Parameters**

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15.

#### 🔵 **Returns**

**Returns**

Nothing

## clear_bit

`clear_bit`

clears one bit of a variable based on its bit index

#### 🔴 **Syntax**

**Syntax**

`clear_bit( <variable> , <bit_index> );`

#### ⚪ **Parameters**

**Parameters**

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15.

#### 🔵 **Returns**

**Returns**

Nothing

## test_bit

`test_bit`

tests a bit index point in a variable to check if it is **TRUE** or **FALSE.**

#### 🔴 **Syntax**

**Syntax**

`test_bit( <variable> , <bit_index> );`

#### ⚪ **Parameters**

**Parameters**

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15.

#### 🔵 **Returns**

**Returns**

**TRUE **if the bit is set, **FALSE **if it is not.

## set_bits

`set_bits`

stores a value into a variable based on its bit index and bit mask.

#### 🔴 **Syntax**

**Syntax**

`set_bits( <variable> , <value>, <bit_index>, <bit_mask> );`

#### ⚪ **Parameters**

**Parameters**

<variable> : any defined variable. <value> : anything that has a value (constants, variables, functions, expressions, etc.) <bit_index> : index point of the bit to be set with a range of 0 to 15. <bit_mask> : bit mask corresponding to the size, in bits, of the value to store (without shifting)

#### 🔵 **Returns**

**Returns**

Nothing

## get_bits

`get_bits`

extracts a value from a variable based on a bit index and bit mask

#### 🔴 **Syntax**

**Syntax**

`get_bits( <variable> , <bit_index>, <bit_mask> );`

#### ⚪ **Parameters**

**Parameters**

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15. <bit_mask> : bit mask corresponding to the size, in bits, of the value to store (without shifting)

#### 🔵 **Returns**

**Returns**

Returns an *int* value

Last updated