๐ Choosing Between `~` and `!`
Best Practice
Use ~ for bitwise signal inversion (gate-level intent).
Use ! for logical truth evaluation (Boolean intent).
Best Practice
Use
Use
~ for bitwise signal inversion (gate-level intent).Use
! for logical truth evaluation (Boolean intent).๐ ~ Bitwise NOT
- Inverts each bit of the input.
- Output is same width as input.
- Synthesizes to inverter gates.
- โ Use when flipping signal polarity or manipulating data paths.
Examples:
~4'b0101 โ 4'b1010
~1'b0 โ 1'b1โ ! Logical NOT
- Returns
1if the entire value is zero, else0. - Output is always 1-bit.
- Synthesizes to zero comparator.
- โ Use in control logic, conditionals, or flag checks.
Examples:
!4'b0000 โ 1'b1
!4'b0101 โ 1'b0๐งฉ Rule of Thumb
| Intent | Operator | Why |
|---|---|---|
| Invert signal bits | ~ | Gate-level, bit-accurate |
| Check if value is zero | ! | Boolean abstraction |
| Control flow decisions | ! | Truthiness of flags |
Last updated on