The boolean or bit operators are available in native RPG as functions, %BITAND - %BITNOT - %BITOR - %BITXOR
%BITAND | %BITNOT | %BITOR | %BITXOR |
---|---|---|---|
If the bits in the same position in all the input parameters are 1, BITAND will return 1 in that position. Otherwise, it will return 0. |
If any bit is 1 in at least one input parameter, BITOR will return 1 in that position. Otherwise, it will return 0. |
If any bit is 1 in only one input parameter, BITXOR will return 1 in that position. Otherwise, it will return 0. |
Each 1 in the input parameter is returned as 0 and each 0 is returned as 1. |
Input 1 1001 0110 Input 2 1111 0000 Returns 1001 0000 |
Input 1 1001 0110 Input 2 1111 0000 Returns 1111 0110 |
Input 1 1001 0110 Input 2 1111 0000 Returns 0110 0110 |
Input 1001 0110 Returns 0110 1001 |
BITAND takes two or more input parameters and returns a value. The parameters and return value are either character or numeric (integer or signed numeric). | BITOR takes two or more input parameters and returns a value. The parameters and return value are either character or numeric (integer or signed numeric). | BITXOR takes two input parameters and returns a value. The parameters and return value are either character or numeric (integer or signed numeric). | BITNOT takes one input parameter and returns a value. The parameter and return value are either character or numeric (integer or signed numeric). |
As a more intuitive alternative, we have created TESTBIT(), SETBITON() and SETBITOFF().
TESTBIT(), SETBITON() and SETBITOFF() are free-form versions of opcodes TESTB, BITON and BITOFF. They are designed to be used
in free form statements. Each takes two parameters. The first parameter is a one character field which is the result or target of the bit
operation. The second parameter contains the bit numbers to be used - in SETBITON and SETBITOFF this can be up to 8 characters in length,
while in TESTBIT the second parameter is only one character in length; for all three, this can be a variable or a constant.
Each is presented as sources in .txt files. Each file contains the prototyped subprocedure and an example of use.
There is a link to the DECIMAL - BINARY - HEXADECIMAL (EBCDIC) conversion table on the left panel.
TestBit () is a function - subprocedure - designed to illustrate a free-form version of the fixed-form opcode TESTB.
It takes a character field, length 1, and a bit reference, range 0 - 7, and returns a 0 or 1 for off or on.
The bit reference is tested against the character field.
returnvalue = TESTBIT(charfield, bit).
where returnvalue = signed numeric field, length 1, value 0 or 1.
... charfield = character field, length 1.
... bit = signed numeric field, length 1.
SetBitOn () is a function - subprocedure - designed to illustrate a free-form version of the fixed-form opcode BITON.
It takes a character field, length 1, and a bit reference, range 0 - 7, There is no return value.
The bit reference is acts on the character field.
SETBITON(charfield, bits).
where charfield = character field, length 1.
... bits = character field of bit positions, length 8.
SetBitOff () is a function - subprocedure - designed to illustrate a free-form version of the fixed-form opcode BITOFF.
It takes a character field, length 1, and a bit reference, range 0 - 7, There is no return value.
The bit reference is acts on the character field.
SETBITOFF(charfield, bits).
where charfield = character field, length 1.
... bits = character field of bit positions, length 8.
You can email us here or use the Contact Us menu tab.