> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/functions/internal-functions/bit-functions.md).

# 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, and how they correlate with bytes and the binary system.

| **Function** | **Description**                  |
| ------------ | -------------------------------- |
| set\_bit     | Sets one bit.                    |
| clear\_bit   | Clears one bit.                  |
| test\_bit    | Tests a bit.                     |
| set\_bits    | Stores a value into a bit index. |
| get\_bits    | Gets a value from the bit index. |

### set\_bit

set\_bit sets one bit of a variable based on its bit index

Code-Snippet

```
set_bit(a,5);
```

Syntax

set\_bit( \<variable>, \<bit\_index> );

Parameters

\<variable> : the variable to modify

\<bit\_index> : index of the bit to be set with a range of 0 to 15 (16-bit firmware) or 0 to 31 (32-bit firmware).

Returns

None

***

### clear\_bit

clear\_bit clears one bit of a variable based on its bit index

Code-Snippet

```
clear_bit(a,5);
```

Syntax

clear\_bit( \<variable> , \<bit\_index> );

Parameters

\<variable> : the variable to modify

\<bit\_index> : index of the bit to be set with a range of 0 to 15 (16-bit firmware) or 0 to 31 (32-bit firmware).

Returns

Nothing

***

### test\_bit

test\_bit tests a bit index point in a value to check if it is set or not (TRUE or FALSE.

Code-Snippet

```
test_bit(b,2);
```

Syntax

test\_bit( \<value> , \<bit\_index> );

Parameters

\<value> : the value to check

\<bit\_index> : index of the bit to be set with a range of 0 to 15 (16-bit firmware) or 0 to 31 (32-bit firmware).

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.

Code-Snippet

```
set_bits(c, 3, 4, 15);
```

Syntax

set\_bits( \<variable> , \<value>, \<bit\_index>, \<bit\_mask> );

Parameters

\<variable> : the variable to modify

\<value> : the value to insert into the variable

\<bit\_index> : the starting index of the bits to be set with a range of 0 to 15 (16-bit firmware) or 0 to 31 (32-bit firmware).

\<bit\_mask> : bit mask to use when inserting the value

Returns

Nothing

***

### get\_bits

get\_bits extracts a value from another value based on a bit index and bit mask

Code-Snippet

```
get_bits(c, 4, 15);
```

Syntax

get\_bits( \<value> , \<bit\_index>, \<bit\_mask> );

Parameters

\<value> : the value to extract the value from

\<bit\_index> : the starting index of the bits to read with a range of 0 to 15 (16-bit firmware) or 0 to 31 (32-bit firmware).

\<bit\_mask> : bit mask to use with the final value

Returns

The value shifted into the low bits from the variable used


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/functions/internal-functions/bit-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
