LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 01-16-2013, 11:50 PM   #1
curious95
Member
 
Registered: Oct 2012
Location: /home/v
Distribution: Slackware 14.0
Posts: 83

Rep: Reputation: Disabled
Post How to add two 4-bit numbers


How do i add two four bit numbers, what are the steps required to do so?
 
Old 01-17-2013, 12:27 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 742
Blog Entries: 2

Rep: Reputation: 193Reputation: 193
What kind of equipment is available? Are you looking for a chart of NAND gates or a line of a C program or what?
 
Old 01-17-2013, 12:37 AM   #3
curious95
Member
 
Registered: Oct 2012
Location: /home/v
Distribution: Slackware 14.0
Posts: 83

Original Poster
Rep: Reputation: Disabled
No ,nothing like that, just how do i add two four bit numbers manually on paper. Like 0000 + 0001.
 
Old 01-17-2013, 12:58 AM   #4
laho
LQ Newbie
 
Registered: May 2009
Distribution: Debian, Ubuntu
Posts: 10

Rep: Reputation: 0
0000
0001
----
0001

It's the same like adding decimal numbers. The same rules apply.
 
Old 01-17-2013, 01:10 AM   #5
curious95
Member
 
Registered: Oct 2012
Location: /home/v
Distribution: Slackware 14.0
Posts: 83

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by laho View Post
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 01:19 AM.
 
Old 01-17-2013, 07:18 AM   #6
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 742
Blog Entries: 2

Rep: Reputation: 193Reputation: 193
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.
 
Old 01-17-2013, 07:31 AM   #7
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,058

Rep: Reputation: 284Reputation: 284Reputation: 284
Quote:
Originally Posted by curious95 View Post
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
 
Old 01-17-2013, 08:04 AM   #8
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,507

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Quote:
Originally Posted by curious95 View Post
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.
 
Old 01-17-2013, 08:58 AM   #9
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,237

Rep: Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071
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 08:59 AM.
 
Old 01-17-2013, 10:29 AM   #10
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 742
Blog Entries: 2

Rep: Reputation: 193Reputation: 193
http://cowbirdsinlove.com/43
 
Old 01-17-2013, 10:32 AM   #11
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,603

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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.
 
Old 01-17-2013, 10:33 AM   #12
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,603

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by linosaurusroot View Post
lol, clever
 
Old 01-17-2013, 10:36 AM   #13
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64&i386, Raspbian Jessie, various VMs
Posts: 3,171

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Like the much repeated phrase "There are 10 types of people in the world: those that understand binary and those that don't.".
 
Old 01-17-2013, 01:07 PM   #14
curious95
Member
 
Registered: Oct 2012
Location: /home/v
Distribution: Slackware 14.0
Posts: 83

Original Poster
Rep: Reputation: Disabled
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 01:14 PM.
 
Old 01-17-2013, 08:49 PM   #15
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,052

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


Reply

Tags
bit


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add decimal numbers in Linux MinuPriya Linux - Newbie 5 08-11-2010 12:31 AM
How to add numbers in JComboBox vibinlakshman Programming 1 02-21-2009 02:10 PM
manipulating 64 bit numbers using 32 bit numbers. rajesh_b Programming 3 09-15-2006 09:03 AM
Help.. how do I add two numbers? Tengil Linux - Newbie 3 03-04-2004 12:58 PM
C, read 8 bit octal numbers, convert to 24 bit binary bamalabs Programming 3 01-20-2004 09:59 AM


All times are GMT -5. The time now is 10:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration