LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-17-2013, 12:50 AM   #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, 01:27 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 869
Blog Entries: 2

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

Rep: Reputation: 216Reputation: 216Reputation: 216
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, 08:31 AM   #7
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
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, 09:04 AM   #8
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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, 09:58 AM   #9
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

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

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

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
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, 11:33 AM   #12
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Originally Posted by linosaurusroot View Post
lol, clever
 
Old 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: Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804
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, 02: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 02:14 PM.
 
Old 01-17-2013, 09:49 PM   #15
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,236

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
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 01:31 AM
How to add numbers in JComboBox vibinlakshman Programming 1 02-21-2009 03:10 PM
manipulating 64 bit numbers using 32 bit numbers. rajesh_b Programming 3 09-15-2006 10:03 AM
Help.. how do I add two numbers? Tengil Linux - Newbie 3 03-04-2004 01:58 PM
C, read 8 bit octal numbers, convert to 24 bit binary bamalabs Programming 3 01-20-2004 10:59 AM


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

Main Menu
Advertisement
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