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