Bit Operations

 
Bit Operations
 
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
Sets one bit
Clears one bit
Tests a bit
Stores a value into a bit index
Gets a value from a bit index
 
1
set_bit
1. set_bit
Sets one bit of a variable based on its bit index
 

Syntax

 
set_bit ( <variable> , <bit_index> );
 

Parameters

 
<variable>  :
any defined variable
<bit_index> :
index point of the bit to be set, range 0~15
2
clear_bit
2. 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, range 0~15
3
test_bit
3. test_bit
Tests a bit index point in a variable to check if it is TRUE or FALSE ( 1 or 0 )
 

Syntax

 
test_bit ( <variable> , <bit_index> );
 

Parameters

 
<variable>  :
any defined variable
<bit_index> :
index point of the bit to be set, range 0~15
 
 

Returns

 
TRUE is the bit is set, FALSE if it is not.
4
set_bits
4. set_bits
Stores a value in to a variable based on its bit index and a 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, range 0~15
<bit_mask>  :
bit mask corresponding to the size, in bits, of the value to store (without shifting)
5
get_bits
5. get_bits
Extracts a balue 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> :
position of the less significant bit in the value to extract, range 0~15
<bit_mask>  :
bit mask corresponding to the size, in bits, of the value to store (without shifting)
 

Returns

 
An integer value.