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

set_bit(a,5);

🔴 Syntax

set_bit ( <variable> , <bit_index> );

Parameters

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

🔵 Returns

Nothing

clear_bit

clear_bit clears one bit of a variable based on its bit index

clear_bit(a,5);

🔴 Syntax

clear_bit( <variable> , <bit_index> );

Parameters

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

🔵 Returns

Nothing

test_bit

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

test_bit(b,2);

🔴 Syntax

test_bit( <variable> , <bit_index> );

Parameters

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

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

set_bits(c, 3, 4, 15);

🔴 Syntax

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

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

Nothing

get_bits

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

get_bits(c, 4, 15);

🔴 Syntax

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

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 an int value

Last updated