# Boolean help. adder and subtractor

1. Jan 26, 2004

### david90

A boolean circuit has 4 inputs, a, b, cin and K. when K=0, the circuit is an adder. When K=1, the ciruit is a subtractor. WHere do I start? [?]

2. Jan 26, 2004

### Hurkyl

Staff Emeritus
Depends on what you're trying to do and what you already know. I imagine you want the circuit for your adder/subtractor, right?

There are lots of ways to go:

You could build an adder, a subtractor, and a chooser circuit.

You could make a truth table and build the circuit from that.

You could analyze the difference between the circuits of an adder and a subtractor and hack it to provide the toggling capability.

3. Jan 26, 2004

### david90

i'm not trying to make a REAL circuit, I just need to know the boolean equation and schematic. I already know what full adder and subtractor look like. I just don't know how to toggle between the two with a 4th input K.

4. Jan 26, 2004

### Hurkyl

Staff Emeritus
Well, my post still applies if you replace "circuit" with "formula".

5. Jan 27, 2004

### david90

not helping

6. Jan 27, 2004

### Guybrush Threepwood

The inputs a and b are they 1 bit or buses?

7. Jan 27, 2004

### Hurkyl

Staff Emeritus
Well, there are two cases, right?

K is false and the formula gives the output of an adder
or
K is true and the formula gives the output of a subtractor

8. Jan 27, 2004

### david90

still not helping. ur just restating my question. I already know there are 2 cases and that k=0 then it is an adder.

9. Jan 27, 2004

### chroot

Staff Emeritus
Consider the naive approach: multiplex the outputs of each, as Hurkyl said.

A two-bit multiplexor looks like this:

(m & s) | (n & ~s)

where & is AND, | is OR, and ~ is NOT. m and n are the two inputs, and s is the select signal.

Does this make sense?

If you want to make the simplest possible formula, replace m and n with the formulas for a 1-bit adder and a 1-bit subtractor. Finally, do all the boolean simplification you can.

Another approach would be to write out a truth table for the whole design -- a K-map -- and do the normal K-map stuff to get the equation.

- Warren

10. Jan 27, 2004

### Hurkyl

Staff Emeritus
There's something special about the way I restated your question; it's directly translatable into a formula!

Is the same as

(~K & (formula for adder)) | (K & (formula for subtractor))

11. Jan 27, 2004

### david90

Thanks i kinda get it now. what is "~"?

12. Jan 28, 2004

### Guybrush Threepwood

it is another way of saying not...
~a = !a = not(a)

13. Jan 28, 2004

### david90

not is an inverter right?

14. Jan 28, 2004

### chroot

Staff Emeritus
Yes, it's an inverter. David, you seem to be completely unprepared to handle this problem. Why? Are you in a class where this was asked? Are you not paying any attention to the lectures?

- Warren

15. Jan 28, 2004

### Janus

Staff Emeritus
Here, I'll give you a hint to get you started:

Think "2's compliment subtraction"

16. Jan 30, 2004

### david90

I have been paying attention in class. It is just that my prof. cares so much about me and the students about getting a job after grad. that he teaches some extra stuff that we're not suppose to learn in ece 204. I'm not sure if I should cuss him out or thank him.

17. Jan 31, 2004

### david90

what is a weighted code (BCD related) and how does it relates to gray code?

18. Jan 31, 2004

### chroot

Staff Emeritus
BCD is simply using three binary digits to encode each digit of a decimal number.

Gray code is a kind of code that allows a system to count in binary by making only one bit toggle between numbers. You can think of as just a variation on the normal counting.

I'm assuming that "weighted code" is what you and I would call "normal" (non-Gray) coding, though most people just call that "binary."

For example, a three-bit Gray code is:

000
001
011
010
110
100
101
111
...
...

- Warren

19. Jan 31, 2004

### wimms

Perhaps best explained why and what is gray code is by looking at application where its needed.
For eg absolute encoders can fail to produce correct code when several bits needs to change at once. Its due to imprecision of readers. To avoid that, gray code is perfect match:
http://mechatronics.mech.nwu.edu/mechatronics/design_ref/sensors/encoders.html [Broken]

http://www.heidenhain.com/phaise2/absed.html [Broken]
http://www.encoders.us/

Last edited by a moderator: May 1, 2017
20. Feb 2, 2004

### david90

My teacher uses 4 bit to describe a number in base ten. My teacher wrote something like 2421 on top of the 4 bits bcd. U have any idea what the hell is 2421? I'll ask my teach if u can't answer. He also went over 9's complement and self complement. Wtf... He went to loco.