Problem Statement:
Add two given numbers without '+' operator.
Download Source Code
Solution:
We will be adding two given numbers using 'AND' and 'XOR' logical operators.
Sum of two number can be achieved with Half adder, if carry is greater than 0 , then it the process is repeated again. This is half adder implementation.
and as per full adder implementation :
Sum = 2*C + S
Below are the different ways of getting the sum using XOR and AND logical operators.
Method 1 :
Method 2:
Method 3:
Method 4:
Please post your comment and suggestions.
Happy Coding !! :)
References:
Wikipedia
Add two given numbers without '+' operator.
Download Source Code
Solution:
We will be adding two given numbers using 'AND' and 'XOR' logical operators.
Fig: Half Adder , S: Sum and C: Carry |
Sum of two number can be achieved with Half adder, if carry is greater than 0 , then it the process is repeated again. This is half adder implementation.
and as per full adder implementation :
Sum = 2*C + S
Below are the different ways of getting the sum using XOR and AND logical operators.
Method 1 :
int add(int a, int b) { while (b != 0) { int carry = a & b; a = a ^ b; b = carry << 1; } return a; }
Method 2:
int add(int a, int b) { if (b == 0) return a; else return add2(a ^ b, (a & b) << 1); }
Method 3:
int add(int a,int b){ int carry= a & b; int sum= a ^ b; carry = 2* carry; sum = sum ^ carry; return sum; }
Method 4:
int add(int a,int b){ return ( 2*( a & b) ) ^ (a ^ b); }
Please post your comment and suggestions.
Happy Coding !! :)
References:
Wikipedia
This comment has been removed by a blog administrator.
ReplyDeleteFirst off I would like to say great blog! I had a quick question in which I'd
ReplyDeletelike to ask if you do not mind. I was interestted to know how you center yourself and clear your thoughts before writing.
I've had a hard time clearing my thoughts in getting my thoughts out.
I do take pleasure in writing however it just seems like the first 10 to 15 minutes tend to
be lost just trying to figure outt how to begin. Any recommendations or tips?
Cheers!
Here is my homepage Las Vegas Whirlpool Repairman
My relatives all the time say that I am wasting my time
ReplyDeletehere at web, except I know I am getting know-how everyday by reading thes pleasant
articles or reviews.
Take a look at my website - online etiquette
Do you mind if I quote a few of your articles as long as
ReplyDeleteI provide credit and sources back to your website?
My blog site is in the exact same niche as yours
and my visitors would definitely benefit from some of the information you present here.
Please let me know if this alright with you. Cheers!
Look into my page; boeing business jet price
Wow! After all I got a website from where I be capable of genuinely get
ReplyDeleteuseful facts regarding my study and knowledge.
Also visit my web blog - ทีฟาว
Hi there to all, because I am actually eager of reading this
ReplyDeleteweb site's post to be updated regularly. It carries
good stuff.
My blog post ... right seo company
Useful info. Lucky me I discovered your site byy
ReplyDeletechance,and I'm surprised why this coincidence didn't cam about
earlier! I bookmarked it.
Feel free to surf to my homepage ... Las Vegas Microwave Repairman
I'm really loving the theme/design of your website.
ReplyDeleteDo you ever run into any internet browser compatibility issues?
A handful of my blog visitors have complained about my
website not working correctly in Explorer but looks great in Chrome.
Do you have any solutions to help fix this issue?
My blog - medical negligence solicitors
Hey there, I think your website might be having browser compatibility issues.
ReplyDeleteWhen I look at your blog site in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up!
Other then that, great blog!
my webpage ... possible search results
Right here is the perfect site for anybody who would like to find out about this topic.
ReplyDeleteYou realize a whole lot its almost hard to argue
with you (not that I personally will need to…HaHa). You definitely put a new
spin on a subject that's been discussed for many
years. Wonderful stuff, just great!
Look at my web blog; tefal standgrill
Quality articles or reviews is the key to interest the viewers
ReplyDeleteto visit the site, that's what this site is providing.
My page: cost to hire a private jet
What's Going down i am new to this, I stumbled upon this I've found It absolutely helpful and it has
ReplyDeleteaided me out loads. I'm hoping to contribute & assist other customers like its aided me.
Great job.
Look at my page social media policies
My spouse and I absolutely love your blog and find a lot of your post's to be what
ReplyDeleteprecisely I'm looking for. Do you offer guest writers to write content available for you?
I wouldn't mind writing a post or elaborating on a lot of the subjects you write with regards to
here. Again, awesome website!
Here is my web-site :: private jet hire london
Hi ,
DeleteNice to hear that , ya sure i encourage you to write and i will post it on your behalf, you can write to me at appcrazyprateek@gmail.com
excellent issues altogether, you simply gained
ReplyDeletea new reader. What might you suggest in regards to
your submit that you simply made a few days ago? Any certain?
Take a look at my page: google search
Woah! I'm really digging the template/theme of
ReplyDeletethis website. It's simple, yet effective. A lot of times it's tough
to get that "perfect balance" between usability and visual appearance.
I must say you've done a great job with this.
Additionally, the blog loads very fast for me on Opera.
Exceptional Blog!
my page :: no win no fee medical claims
Great article.
ReplyDeletemy web site :: charter flights from uk
Ahaa, its pleasant dialogue regarding this paragraph at this place
ReplyDeleteat this weblog, I have read all that, so now me also commenting here.
Also visit my homepage :: tefal optigrill купить
Thanks a bunch for sharing this with all folks you actually realize what you are speaking approximately!
ReplyDeleteBookmarked. Please also seek advice from my site =). We could have a hyperlink change arrangement among us
Here is my weblog :: website promotion
You ought to be a part of a contest for one of the finest blogs online.
ReplyDeleteI will highly recommend this site!
My web blog; mobile website
Very nice article, exactly what I was looking for.
ReplyDeleteFeel free to surf to my web-site - digital agency in london
When someone writes an paragraph he/she maintains the thought of a user in his/her mind that how a user can know it.
ReplyDeleteSo that's why this piece of writing is perfect.
Thanks!
My homepage: clinical negligence london