Skip to content
๐Ÿ”€ Choosing Between `~` and `!`

๐Ÿ”€ Choosing Between `~` and `!`

Best Practice 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 1 if the entire value is zero, else 0.
  • 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

IntentOperatorWhy
Invert signal bits~Gate-level, bit-accurate
Check if value is zero!Boolean abstraction
Control flow decisions!Truthiness of flags
Last updated on