|
|
|
|
|
- Use
- Binary operators
- Binary AND, OR and exclusive OR
- Binary NOT
- Shift operators
- Syntaxes
- Notes
- Operator for direct access to the bits
- Access to a bit
- Access to a 1, 2 or 4-byte integer
- Access to the value of several bits
The operations on binary values are performed: - with the WLanguage functions: BinaryAND, BinaryOR, BinaryNOT, BinaryXOR.
- with specific operators: binary operators, operators for right or left offset, operator for accessing the bits.
Binary AND, OR and exclusive OR The following syntaxes can be used: - Binary AND: <Value 1> & <Value 2>
- Binary OR: <Value 1> | <Value 2>
- Binary exclusive OR: <Value 1> || <Value 2>
The type of result depends on the type of the operands: | | | | Value 2 Value 1 | 4-byte integer | 8-byte integer | Other | 4-byte integer | 4-byte integer | 8-byte integer | 4-byte integer | 8-byte integer | 8-byte integer | 8-byte integer | 8-byte integer | Other | 4-byte integer | 8-byte integer | 8-byte integer |
Binary NOT The syntax is as follows: ~ <Value> The type of result depends on the operand type: | | Operand | Result | 4-byte integer | 4-byte integer | 8-byte integer | 8-byte integer | Other | 8-byte integer |
Syntaxes - Offset to left:
<Value 1> bitLeftShift <Value 2>> bitLeftShift(<Value 1>, <Value 2>)
- Offset to right:
<Value 1> bitRightShift <Value 2>> bitRightShift(<Value 1>, <Value 2>)
Notes - The bits of <Value 1> are shifted from <Value 2> bits to the right or to the left.
For example:
bitLeftShift(4,1) // Returns 8
Indeed, 4 in decimal corresponds to 0100 in binary. Shifted from 1 bit to the left, we get 1000 in binary that corresponds to 8 in decimal.
bitRightShift(4,2) // Returns 1
Indeed, 4 in decimal corresponds to 0100 in binary. Shifted from 2 bits to the right, we get 0001 in binary that corresponds to 1 in decimal. - The bits that exceed the size of <Value 1> are ignored. For example:
bitLeftShift(4,30) // Returns 0 bitRightShift(4,4) // Returns 0
- If <Value 2> is greater than the size of <Value 1> (32 for a 4-byte integer and 64 for an 8-byte integer), the result is always 0. For example:
bitLeftShift(4,35) // Returns 0
- The type of result depends on the type of the operand:
| | Operand Value 1 | Result | 4-byte integer | 4-byte integer | 8-byte integer | 8-byte integer | Other | 8-byte integer |
Operator for direct access to the bits
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|