LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to add two 4-bit numbers (http://www.linuxquestions.org/questions/programming-9/how-to-add-two-4-bit-numbers-4175445961/)

curious95 01-16-2013 11:50 PM

How to add two 4-bit numbers
 
How do i add two four bit numbers, what are the steps required to do so?

linosaurusroot 01-17-2013 12:27 AM

What kind of equipment is available? Are you looking for a chart of NAND gates or a line of a C program or what?

curious95 01-17-2013 12:37 AM

No ,nothing like that, just how do i add two four bit numbers manually on paper. Like 0000 + 0001.

laho 01-17-2013 12:58 AM

0000
0001
----
0001

It's the same like adding decimal numbers. The same rules apply.

curious95 01-17-2013 01:10 AM

Quote:

Originally Posted by laho (Post 4871905)
0000
0001
----
0001

I don't think so i'm talking about binary addition(base 2). I don't know how to do it. But i could use an example showing me what to do.

linosaurusroot 01-17-2013 07:18 AM

In decimal when you get to 10 you write a single digit in the current column and carry 1 to the next column (left, more significant). Binary is just the same except it's 2 that brings you to the carry - there are only two single digits 0 and 1.

danielbmartin 01-17-2013 07:31 AM

Quote:

Originally Posted by curious95 (Post 4871882)
How do i add two four bit numbers, what are the steps required to do so?

There are on-line tutorials. This is a good one:
http://www.math.grin.edu/~rebelsky/C...student-binary

Daniel B. Martin

dwhitney67 01-17-2013 08:04 AM

Quote:

Originally Posted by curious95 (Post 4871915)
I don't think so i'm talking about binary addition(base 2). I don't know how to do it. But i could use an example showing me what to do.

An example was already given.

Here's a few other examples:
Code:

    0010
+  0101
  ------
    0111


    0011
+  0001
  ------
    0100


    0101
+  1011
  -------
    0000    <--- Note in this example, the most significant bit of the result rolled out of existence.


sundialsvcs 01-17-2013 08:58 AM

It's exactly like base 10: 0 + 1 = 1 ... etc[/b] ... 1 + 1 = 1 carry 1.

It does take a bit of getting used two ... ;)

linosaurusroot 01-17-2013 10:29 AM

http://cowbirdsinlove.com/43

suicidaleggroll 01-17-2013 10:32 AM

It's the same as adding in any other base. Base 2, base 8, base 10, base 16, it all works the same.

Start at the LSB, add the numbers together. If you overflow that digit (2 in base 2, 8 in base 8, 10 in base 10, etc), then carry the 1 into the next most significant column and repeat.

suicidaleggroll 01-17-2013 10:33 AM

Quote:

Originally Posted by linosaurusroot (Post 4872270)

lol, clever

273 01-17-2013 10:36 AM

Like the much repeated phrase "There are 10 types of people in the world: those that understand binary and those that don't.".

curious95 01-17-2013 01:07 PM

Thank you, i've understood what to do :) Sorry laho guess i thought binary addition would be 'harder' than that.

jlinkels 01-17-2013 08:49 PM

Quote:

Originally Posted by curious95 (Post 4872382)
Thank you, i've understood what to do :) Sorry laho guess i thought binary addition would be 'harder' than that.

Try subtraction :)
jlinkels


All times are GMT -5. The time now is 12:56 AM.