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

πŸ”΄ 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.

πŸ”΄ 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.

πŸ”΄ 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

πŸ”΄ 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

Was this helpful?