All the bit operators are arithmetic operators, this means that they can only be used when Trinc-Prolog is evaluating arithmetic expressions.
Perform the bit AND operator. Only 1 and 1 remain 1, all other bits are set to 0.
| Examples | |
| X is 22 /\ 2. | succeeds, X= 2 |
| X is 22 /\ 12. | succeeds, X = 4 |
Perform the bit OR operator, all bits become 1 except when two 0 bits are OR-ed together.
| Examples | |
| X is 22 \/ 2. | succeeds, X= 22 |
| X is 22 \/ 12. | succeeds, X = 30 |
Perform the bit complement operation, the sign of each bit is reversed.
| Examples | |
| X is \ 16. | succeeds, X= -17 |
| X is \ 1. | succeeds, X = -2 |
Shift the bits a number of positions to the left, the bits on the right side are filled with 0 bits. Shifting a number 1 bit to the left is equal to multiplying by 2.
| Examples | |
| X is 16 << 1. | succeeds, X = 32 |
| X is 16 << 2. | succeeds, X = 64 |
Shift the bits a number of positions to the right, the bits on the left side are filled with 0 bits. Shifting a number 1 bit to the right is equal to dividing the number by 2.
| Examples | |
| X is 16 >> 1. | succeeds, X = 8 |
| X is 16 >> 2. | succeeds, X = 4 |
see also: arithmetic comparisons arithmetic in Prolog is/2