Home › Practice › RTL Design › Flip and add one

Flip and add one

EasyRTLcombinationalarithmetic

A thermometer stores temperatures from -8 to +7 in 4 bits. Given a temperature x, how do you get -x?

Concept first. Computers store negative numbers in two's complement. With 4 bits, 0000 to 0111 are 0 to 7 and 1000 to 1111 are -8 to -1. There is a two-step recipe to negate a number: invert every bit, then add one. Example: 3 is 0011; inverted it is 1100; plus one it is 1101, which is -3. Try it on 1 and on 0 to see it work. Then try 1000 (that is -8) and see what happens: -8 has no positive partner in 4 bits.

What to build.

Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← Carry passed hand to handOne circuit, two jobs →