Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org [SOLVED] How to add two 4-bit numbers
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 01-17-2013, 12:50 AM #1 curious95 Member   Registered: Oct 2012 Location: /home/v Distribution: Slackware 14.0 Posts: 83 Rep: How to add two 4-bit numbers How do i add two four bit numbers, what are the steps required to do so?
 01-17-2013, 01:27 AM #2 linosaurusroot Member   Registered: Oct 2012 Distribution: OpenSuSE,RHEL,Fedora,OpenBSD Posts: 869 Blog Entries: 2 Rep: What kind of equipment is available? Are you looking for a chart of NAND gates or a line of a C program or what?
 01-17-2013, 01:37 AM #3 curious95 Member   Registered: Oct 2012 Location: /home/v Distribution: Slackware 14.0 Posts: 83 Original Poster Rep: No ,nothing like that, just how do i add two four bit numbers manually on paper. Like 0000 + 0001.
 01-17-2013, 01:58 AM #4 laho LQ Newbie   Registered: May 2009 Distribution: Debian, Ubuntu Posts: 10 Rep: 0000 0001 ---- 0001 It's the same like adding decimal numbers. The same rules apply.
01-17-2013, 02:10 AM   #5
curious95
Member

Registered: Oct 2012
Location: /home/v
Distribution: Slackware 14.0
Posts: 83

Original Poster
Rep:
Quote:
 Originally Posted by laho 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.

Last edited by curious95; 01-17-2013 at 02:19 AM.

 01-17-2013, 08:18 AM #6 linosaurusroot Member   Registered: Oct 2012 Distribution: OpenSuSE,RHEL,Fedora,OpenBSD Posts: 869 Blog Entries: 2 Rep: 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.
01-17-2013, 08:31 AM   #7
danielbmartin
Senior Member

Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Rep:
Quote:
 Originally Posted by curious95 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

01-17-2013, 09:04 AM   #8
dwhitney67
Senior Member

Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep:
Quote:
 Originally Posted by curious95 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.

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.```

 01-17-2013, 09:58 AM #9 sundialsvcs Guru   Registered: Feb 2004 Location: SE Tennessee, USA Distribution: Gentoo, LFS Posts: 5,455 Rep: 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 ... Last edited by sundialsvcs; 01-17-2013 at 09:59 AM.
 01-17-2013, 11:29 AM #10 linosaurusroot Member   Registered: Oct 2012 Distribution: OpenSuSE,RHEL,Fedora,OpenBSD Posts: 869 Blog Entries: 2 Rep: http://cowbirdsinlove.com/43
 01-17-2013, 11:32 AM #11 suicidaleggroll Senior Member Contributing Member   Registered: Nov 2010 Location: Colorado Distribution: OpenSUSE, CentOS Posts: 3,212 Rep: 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.
01-17-2013, 11:33 AM   #12
suicidaleggroll
Senior Member

Registered: Nov 2010
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep:
Quote:
 Originally Posted by linosaurusroot http://cowbirdsinlove.com/43
lol, clever

 01-17-2013, 11:36 AM #13 273 Senior Member   Registered: Dec 2011 Location: UK Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs Posts: 3,559 Rep: Like the much repeated phrase "There are 10 types of people in the world: those that understand binary and those that don't.".
 01-17-2013, 02:07 PM #14 curious95 Member   Registered: Oct 2012 Location: /home/v Distribution: Slackware 14.0 Posts: 83 Original Poster Rep: Thank you, i've understood what to do Sorry laho guess i thought binary addition would be 'harder' than that. Last edited by curious95; 01-17-2013 at 02:14 PM.
01-17-2013, 09:49 PM   #15
Senior Member

Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,236

Rep:
Quote:
 Originally Posted by curious95 Thank you, i've understood what to do Sorry laho guess i thought binary addition would be 'harder' than that.
Try subtraction

 Tags bit