Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- //function for Binary Subtraction
- int binSubtracton(int a, int b)
- {
- int carry;
- //get 2's compliment of b and add in a
- b = binAddition(~b, 1);
- while (b != 0) {
- //find carry and shift it left
- carry = (a & b) << 1;
- //find the sum
- a = a ^ b;
- b = carry;
- }
- return a;
- }
- int main()
- {
- int a,b;
- cin>>a>>b;
- cout<<binSubtracton(a,b)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement