Home / Learn Verilog / Absolute Value Circuit

Absolute Value Circuit

Negate if negative.

The gistNegate if negative.

The idea, explained simply

absI0I1YSELsign ? -a : a
abs

The basic idea

If the sign bit is 1 negate the value.

Why this comes up

Distance, magnitude calculations.

The mechanics

Mux between a and -a.

Where it is used

  • Everyday RTL design
  • FPGA and ASIC projects
  • Testbenches and debugging

Try it

absVerilog: edit and run

-128 has no positive 8-bit twin.

Quick check

1. abs(-128) in 8-bit signed gives...