Boolean help. adder and subtractor

  • Thread starter david90
  • Start date
  • Tags
    Adder
In summary, 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.
  • #1
david90
312
2
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? [?]
 
Engineering news on Phys.org
  • #2
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
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
Well, my post still applies if you replace "circuit" with "formula".
 
  • #5
not helping
 
  • #6
Originally posted by david90
A boolean circuit has 4 inputs, a, b, cin and K. when K=0, the circuit is an adder.

The inputs a and b are they 1 bit or buses?
 
  • #7
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
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
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
still not helping. ur just restating my question. I already know there are 2 cases and that k=0 then it is an adder.

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


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

Is the same as

(~K & (formula for adder)) | (K & (formula for subtractor))
 
  • #11
Thanks i kinda get it now. what is "~"?
 
  • #12
Originally posted by david90
what is "~"?

it is another way of saying not...
~a = !a = not(a)
 
  • #13
not is an inverter right?
 
  • #14
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
Here, I'll give you a hint to get you started:

Think "2's compliment subtraction"
 
  • #16
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
what is a weighted code (BCD related) and how does it relates to gray code?
 
  • #18
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
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

http://www.heidenhain.com/phaise2/absed.html
http://www.encoders.us/
 
Last edited by a moderator:
  • #20
Originally posted by chroot
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

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.
 
  • #21
Oops, I meant 4 bits for BCD, sorry.

The "2421" is just one possible weighting scheme for BCD. The BCD code 1111 = 2 + 4 + 2 + 1 = 9 decimal. Normal binary would be "8421," and this is just a variant.

- Warren
 
  • #22
considering that you have over a 1k posts, it is ok to make a mistake .:smile:

I did some web searching and now I know what 8421 mean but I still don't get how it is useful. Why is weighted code necessary?

I tried converting the binary of the gray code into decimal but it didn't come out the same. why?
 
Last edited:
  • #23
Well, all place-system numerals are weighted. In decimal, the weights are:

first digit on the right: one's place
next digit to the left: ten's place
next digit to the left: hundred's place
next digit to the left: thousand's place

and so on. In binary, the places are:

first digit on the right: one's place
next digit to the left: two's place
next digit to the left: four's place
next digit to the left: eight's place

and so on.

Someone, somewhere, decided to make the leftmost digit in his BCD coding mean "two's place" instead of "eight's place." I honestly don't know why this person did it, why it's better. I'm used to BCD just meaning using 4 bits to represent a decimal digit, using normal binary. Thus the number 1983 would be:

0001 1001 1000 0011

As far as Gray code: Gray code is not binary. It doesn't follow the place-system like other numbers. Gray code is an alternative way to count that does not involve flipping more than one bit at a time. A Gray code number is not binary.

- Warren
 
  • #24
The BCD code 1111 = 2 + 4 + 2 + 1 = 9 decimal.

Wouldn't the BCD code for decimal 9 be 1001? 1111 is not BCD but binary for decimal 15.

Example: BCD=0001100000000110
=0001 1000 0000 0110
Digital= 1 8 0 6 or 1806
 
  • #25
Originally posted by dlgoff
Wouldn't the BCD code for decimal 9 be 1001?
Not when the non-binary weighting rule "2421" is being used -- which is what david90 was asking about.

The main reason for using 2421 over normal 8421 binary is simply that, with 2421, there are no invalid four-bit strings.

- Warren
 
  • #26
The main reason for using 2421 over normal 8421 binary is simply that, with 2421, there are no invalid four-bit strings.

Thanks. I didn't know about "2421 BCD". Is this what it's called?

Regards
 
  • #27
Originally posted by dlgoff
Thanks. I didn't know about "2421 BCD". Is this what it's called?
You got me. I've never even heard of anyone using this until david90 described it.

- Warren
 
  • #28
Subtractor is generally not needed

I'm not exactly sure what you're after, however I might point out
that computer systems are almost never designed with logic that
can both 'add' and 'subtract'. It simply isn't needed. We can
subtract simply by complementing the 'subtrahend' (number on the
bottom) and then adding. It gets us the same result and the
circuitry is simpler.

To illustrate, I give you some examples in decimal. Binary is
simpler, but decimal is more familiar to most of us.
(Unfortunately, we have ten fingers, so our numbering system
came about based on the number ten.)

The complement of an integer, for practical purposes, can be
based upon the size of the number, having a 'one' in the
position just larger than the largest value that we must deal
with and 'zeros' in the remaining positions. Thus if our
number range is "0 to 9", then the complement will be based on
the number "10"; if our range is 0 to 999 (or any other
value from 100 to 999) the complement will be based on the value
1000; etc. Partial examples are as follows:

10 1000 1,000,000
Number Complement Number Complement Number Complement
9 1 999 1 999,999 1
8 2 998 2 999,998 2
7 3 997 3 999,997 3
6 4 - - - -
5 5 - - - -
4 6 - - - -
3 7 3 997 3 999,997
2 8 2 998 2 999,998
1 9 1 999 1 999,998
0 10 0 1000 0 1,000,000


If we thus want to subtract two numbers, we simply take the
complement of the subtrahend, and add it. Thus for example:

7 7
-4 becomes +6
3
But what, you say, about the '1'? Remember, that the highest
value in this system is '9', so the one in the next highest
position "drops off the edge of the world. It doesn't exist
in our system. Probably a better example would be to subtract
4 from 7 in a system with 999,999 as its largest
necessary value. We would then have:

7 7
-4 then becomes +999,996
(1),000,003

Where that upper '1' is beyond the applicable range of the system,
so the value is simply "3". In a practical system, the range might
be much longer, so there might be a great number of "leading zeroes".
These are simply dropped, since they add no value. As another
example, in a six digit system (with 999,999 as maximum):

63,247 63,247
-34,567 we get +965,433
(1),028,680 which is: 28,680

The question then is, "How do we know the complement of the value
34,567 without having some huge conversion table. The answer
is to simply take the inversion of each digit, and then add one.
The inversions in the decimal system are:

9 - 0
8 - 1
7 - 2
6 - 3
5 - 4
4 - 5
3 - 6
2 - 7
1 - 8
0 - 9

Thus, the inversion of 34,567 is 65,432, and when we add '1'
we get 65,433, which when added gives us the correct
subtraction answer. In binary the rules are the same, except
that it is much easier. We simply invert (negate/not) all
the digits (by changing all "1's" to "0", and all "0's" to "1")
and then add "1". Thus, the complement of "101011" simply
becomes "010100 + 1 = 010101". We simply then "add" the two
values and the upper "1" simply carries right out of the
system. Some people talk about an "end around carry". You
may do so, but remember that that is simply a crutch".
It's a convenient way to explain what to do with the "1's"
but it is not really explanatory of what is happening. I
hope this gives some insight.
 
  • #29
Retry

I'm resending a table that I had put in. Before, the items were in separate and distinct columns, however when submitted, the system squeezed out all the spaces, thus running the columns together. This time I use tabs. If these are squeezed out, good luck.

10 1000 1,000,000
Number Complement Number Complement Number Complement
9 1 999 1 999,999 1
8 2 998 2 999,998 2
7 3 997 3 999,997 3
6 4 - - - -
5 5 - - - -
4 6 - - - -
3 7 3 997 3 999,997
2 8 2 998 2 999,998
1 9 1 999 1 999,998
0 10 0 1000 0 1,000,000
 
  • #30
Kenneth, try using search and replace in notepad or some other text editor to swap out two spaces for a space and a   which is the html symbol for a non-breaking space. Here's your chart with that swap done.

--------------------------------------------------------------------

       10                                1000                    1,000,000
Number Complement      Number  Complement   Number  Complement
9            1                     999           1             999,999          1
8            2                     998           2             999,998          2
7            3                     997           3             999,997          3
6            4                      -            -               -              -  
5            5                      -            -               -              -
4            6                      -            -               -              -
3            7                      3          997               3        999,997
2            8                      2          998               2        999,998
1            9                      1          999               1        999,998
0           10                      0         1000              0      1,000,000
 
Last edited:
  • #31
Cliff,

It's even easier just to use the [ code ] tag.

- Warren
 

FAQ: Boolean help. adder and subtractor

1. What is a Boolean adder?

A Boolean adder is a digital circuit that performs the addition operation on two binary numbers. It consists of logic gates that generate the sum and carry outputs based on the input values.

2. How does a Boolean adder work?

A Boolean adder works by using logic gates such as AND, OR, and XOR to perform the addition operation on two binary numbers. The inputs are fed into the logic gates, and the outputs are generated based on the Boolean logic equations.

3. What is the difference between a half adder and a full adder?

A half adder can only add two single-bit binary numbers and does not account for any carry from previous additions. A full adder, on the other hand, can add two single-bit binary numbers as well as account for any carry from previous additions.

4. What is a Boolean subtractor?

A Boolean subtractor is a digital circuit that performs the subtraction operation on two binary numbers. It uses logic gates such as AND, OR, and NOT to generate the difference output based on the input values.

5. How does a Boolean subtractor work?

A Boolean subtractor works by using logic gates to perform the subtraction operation on two binary numbers. The inputs are fed into the logic gates, and the outputs are generated based on the Boolean logic equations. The borrow output is also generated to account for any borrow from previous subtractions.

Similar threads

Replies
2
Views
27K
Replies
3
Views
1K
Replies
1
Views
2K
Replies
1
Views
857
Replies
5
Views
2K
Replies
1
Views
2K
Replies
6
Views
7K
Replies
3
Views
2K
Replies
1
Views
1K
Back
Top