Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 22-08-2007, 10:34 PM   #1 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Addition of 2 numbers without + sign


Hello Friends,

Here is the another assignment problem.
This time, I've to add 2 numbers without using + sign.

I got some solutions as ..
Code:
a+b = a - (-b)               ====> This I don't want !!!
This works on paper ===>
Code:
                1 1
a= 6 ==>    0 1 1 0
                           +
b=10==>    1 0 1 0
               ---------
c=16==>  1 0 0 0 0
So, this is the BINARY ADDITION.

But how I can implement it ???

I NEED LOGIC ONLY !!! NO PROGRAM PLEASE !!!
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 22-08-2007, 10:47 PM   #2 (permalink)
The Lord of Death
 
Yamaraj's Avatar
 
Join Date: May 2005
Location: यमलोक
Posts: 253
Default Re: Addition of 2 numbers without + sign

Use bitwise operators.
Yamaraj is offline  
Old 22-08-2007, 10:49 PM   #3 (permalink)
Alpha Geek
 
sam_1710's Avatar
 
Join Date: May 2006
Posts: 755
Default Re: Addition of 2 numbers without + sign

^^ how do you use single "&" and "|" in this prg??. .
i dint get the required answer!!
__________________
C2D E8400, MSI P45 Neo-F, Sapphire HD4850, Dell 2409W, OCZ 2*1GB RAM + 1*2GB Transcend + 1*1GB Transcend , Seagate 1TB + 2*Seagate 80GB, 600W SMPS, APC 600VA, Creative EP630, Sennheiser HD202 :)
sam_1710 is offline  
Old 22-08-2007, 10:51 PM   #4 (permalink)
Hey here is the aks
 
arunks's Avatar
 
Join Date: Jan 2006
Location: punjab
Posts: 805
Default Re: Addition of 2 numbers without + sign

i think we can use | (OR operator ) to perform addition... plz check i m not sure
this program is giving corect answer thats why i m saying
main()
{
int a=3,b=4,c=0;
c=a|b;
printf("%d",c)
}
__________________
yours truly
arun
The aks!!

have a nice day
arunks is offline  
Old 22-08-2007, 11:45 PM   #5 (permalink)
Alpha Geek
 
sam_1710's Avatar
 
Join Date: May 2006
Posts: 755
Default Re: Addition of 2 numbers without + sign

^^ nope dats does not give da ans..
It does not give for some values..
Try givin a=8 and b=8, or ... 15 and 10 or so..

_____________________
This code works for certain numbers...

Code:
if(a<b)
{
     t=a;
     a=b;
     b=t;
}
printf("%d",a^b);
_____________
EDIT
got it..
Code:
unsigned int add(unsigned int a, unsigned int b)
{      unsigned int c=0, r=0, t=~0;
        for(t= ~0;t;t>>=1)
       {       r<<=1;
                r|=(a^b^c)&1;
                c=((a|b)&c|a&b)&1;
                a>>=1;
                b>>=1;
         }
        for (t=~0,c=~t;t;t>>=1)
         {     c<<= 1;
                c|= r&1;
                r>>= 1;
         }     return c;
}
From here
__________________
C2D E8400, MSI P45 Neo-F, Sapphire HD4850, Dell 2409W, OCZ 2*1GB RAM + 1*2GB Transcend + 1*1GB Transcend , Seagate 1TB + 2*Seagate 80GB, 600W SMPS, APC 600VA, Creative EP630, Sennheiser HD202 :)

Last edited by sam_1710; 22-08-2007 at 11:47 PM. Reason: Automerged Doublepost
sam_1710 is offline  
Old 22-08-2007, 11:58 PM   #6 (permalink)
The Lord of Death
 
Yamaraj's Avatar
 
Join Date: May 2005
Location: यमलोक
Posts: 253
Default Re: Addition of 2 numbers without + sign

Code:
int bitAdd(int x, int y)
{
   return (x&y) ? bitAdd(x^y, (x&y) << 1) : (x^y);
}
Yamaraj is offline  
Old 23-08-2007, 12:12 AM   #7 (permalink)
Alpha Geek
 
sam_1710's Avatar
 
Join Date: May 2006
Posts: 755
Default Re: Addition of 2 numbers without + sign

^^^ thats a nice extension to my first code!!
__________________
C2D E8400, MSI P45 Neo-F, Sapphire HD4850, Dell 2409W, OCZ 2*1GB RAM + 1*2GB Transcend + 1*1GB Transcend , Seagate 1TB + 2*Seagate 80GB, 600W SMPS, APC 600VA, Creative EP630, Sennheiser HD202 :)
sam_1710 is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
serial numbers of win xp sp2 pravesh_4766 Software Q&A 3 30-04-2006 08:32 PM
Motorolla addition to RAZR family abracadabra Mobiles and Tablets 3 01-12-2005 11:17 AM
Usb pin numbers beyondthegracefgod Peripherals 5 07-11-2004 02:51 PM

 
Latest Threads
- by Tenida
- by Charan
- by abhidev

Advertisement




All times are GMT +5.5. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2