0

Disclaimer, I'm a total electronics/circuit noob so sorry if this is really simple! But I've just built a 4-bit less-than comparator in CircuitVerse (outputs whether A < B), and I want to use a 1-bit input to signal whether the inputs are signed or unsigned (so an input of 1 will mean it's signed).

The project prompt I'm following says that for signed comparison you just need to negate the data inputs to the highest order comparator. But how exactly would I do this using CircuitVerse?

I understand I have a 1-bit input block, and when it's 1 I need to negate A3 and B3 (the highest order inputs, going from A0,B0 -> A3,B3) so I'll need 2 not-gates. I just don't understand how to route the 2 highest order bits through the signed bits, so that they only negate when the signed bit is 1.

1 Answers1

0

I don't know CircuitVerse, but what you're looking for is an exclusive-or (xor) gate. Consider the truth table for xor:

A B Y
0 0 0
0 1 1
1 0 0
1 1 1

While the typical way to think of xor is "output 1 if and only if A or B is set", you can also think of it as "if bit B is set, output !A, otherwise output A".

You can utilise this to selectively invert bits:

schematic

simulate this circuit – Schematic created using CircuitLab

I also built an interactive simulation on Falstad in case you want to play around with the logic and get more familiar with how it works.

Polynomial
  • 10,562
  • 5
  • 47
  • 88