InstallShield 2018 ยป InstallScript Language Reference
Bit, or bitwise, operators allow you to manipulate individual bits in a numeric variable. In order to use the operators effectively, you need to be familiar with binary notation. This topic gives you an overview of binary operators, but it does not try to teach you binary notation.
Bit operators work like logical operators, with one exception: logical operators work with expressions, bit operators work with bits. The InstallScript compiler recognizes the bitwise operators listed in the table below:
Symbol |
Operator |
Explanation |
& |
BitAND |
BitAND sets a bit in the result to 1 (TRUE) only if the bits in both operands are 1s; otherwise, the result is 0 (FALSE). |
| |
BitOR |
Bit inclusive OR sets a bit in the result to 0 only if the bits in the operands are 0; otherwise, the result is 1. |
^ |
BitXOR |
Bit exclusive OR sets a bit in the result to 1 if the corresponding bits in the operands are different (one 1, the other 0). Otherwise, the result is 0. |
~ |
BitNOT |
BitNOT is a unary operator that reverses every bit in the operand, changing every 1 to a 0 and vice versa, as in the following example: ~00001100 The result is 11110011. |
<< |
Shift left |
Moves bits a specified number of bits to the left. For example, the expression shown below moves bits three spaces to the left: 00001100 << 3 The result is 01100000. |
>> |
Shift right |
Moves bits a specified number of bits to the right. For example, the expression shown below moves bits two spaces to the right: 00001100 >> 2 The result is 00000011. |
Shift operations work the same way in InstallScript that they do in the C language. When you shift by two bits to the right (>> 2), the two bit values furthest to the right are lost. The other bit values are shifted to the right two places, and the sign bit is shifted into the empty bits.
You can use shift operations to multiply and divide a value by a power of 2. Left-shifting an integer by n has the same effect as multiplying the number by 2 to the power of n. Right-shifting an integer by n has the same effect as dividing the number by 2 to the power of n.
See Also
InstallShield 2018 Help LibrarySeptember 2018 |
Copyright Information | Flexera |