GPC Developer Guides
...
Functions
Internal Functions

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

GPC


🔴 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

GPC


🔴 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.

GPC


🔴 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.

GPC


🔴 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

GPC


🔴 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