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.

set_bit

set_bit sets one bit of a variable based on its bit index

set_bit(a,5);

set_bit ( <variable> , <bit_index> );

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

Nothing

clear_bit

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

clear_bit(a,5);

clear_bit( <variable> , <bit_index> );

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

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);

test_bit( <variable> , <bit_index> );

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

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);

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

<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)

Nothing

get_bits

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

get_bits(c, 4, 15);

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

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

Last updated