Skip to content

Commit 2800a7f

Browse files
mattduerrmeierswaroopch
authored andcommitted
op_exp : explanation + example for bit-wise
I think adding explanation + example for the bit-wise AND, OR and XOR could make it easier to understand them. The bit-wise invert has a link for more details. I left it as it is.
1 parent 02e01e2 commit 2800a7f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

op_exp.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ Here is a quick overview of the available operators:
6161
- `11` is represented in bits by `1011` which when right shifted by 1 bit gives `101`which is the decimal `5`.
6262

6363
- `&` (bit-wise AND)
64-
- Bit-wise AND of the numbers
65-
- `5 & 3` gives `1`.
66-
64+
- Bit-wise AND of the numbers: if both bits are `1`, the result is `1`. Else it's `0`.
65+
- `5 & 3` gives `1` (`0101 & 0011` gives `0001`)
66+
6767
- `|` (bit-wise OR)
68-
- Bitwise OR of the numbers
69-
- `5 | 3` gives `7`
70-
71-
- `^` (bit-wise XOR)
72-
- Bitwise XOR of the numbers
73-
- `5 ^ 3` gives `6`
68+
- Bitwise OR of the numbers: if both bits are `0`, the result is `0`. Else it's `1`.
69+
- `5 | 3` gives `7` (`0101 | 0011` gives `0111`)
70+
71+
- `^` (bit-wise XOR)
72+
- Bitwise XOR of the numbers: if both bits (`1 or 0`) are the the same, the result is `0`. Else it's `1`.
73+
- `5 ^ 3` gives `6` (`O101 ^ 0011` gives `0110`)
7474

7575
- `~` (bit-wise invert)
7676
- The bit-wise inversion of x is -(x+1)

0 commit comments

Comments
 (0)