Addition of two Binary numbers using C
The operation of adding two binary numbers is one of the fundamental tasks performed by a digital computer. The four basic addition operations are 0 + 0 = 0, 1 + 0 = 1, 0 + 1 = 1 and 1 + 1 = 10. In the first three operations, each binary addition gives sum as one bit , i.e. , either 0 or 1.But the fourth addition operation gives a sum that consists of two binary digits. In such result of the addition, lower significant bit is called as the sum bit, whereas the higher significant bit is called as the carry bit.
Binary Addition of Two Bits
| 0 | 0 | 1 | 1 |
| + 0 | + 1 | + 0 | + 1 |
| 0 | 1 | 1 | (carry) 1←0 |
C Program for addition of two binary Numbers:
#include <stdio.h>
#include <conio.h>
int main()
{
long int binary1, binary2;
int i = 0, remainder = 0, sum[20];
printf("Enter any first binary number :");
scanf("%ld", &binary1);
printf("Enter any second binary number :");
scanf("%ld", &binary2);
while(binary1!= 0 || binary2 != 0)
{
sum[i++] = (binary1 % 10 + binary2 % 10 + remainder) % 2;
remainder = (binary1 % 10 + binary2 % 10 + remainder) / 2;
binary1 = binary1 / 10;
binary2 = binary2 / 10;
}
if(remainder != 0)
sum[i++] = remainder;
--i;
printf("Sum of two binary numbers :");
while(i >= 0)
printf("%d", sum[i--]);
return 0;
}


This is a very informative and useful blog. I really enjoyed reading the content because it is simple, clear, and easy to understand. The information shared in this article is helpful for readers who want to learn more about the topic. I especially liked how the points were explained with practical details and useful suggestions. Such well-written blogs make it easier to discover new ideas and gain valuable knowledge. Thank you for sharing this helpful information. I look forward to reading more interesting and informative articles like this in the future. Keep up the great work and continue sharing valuable content.
ReplyDeleteBest Fashion Designing institute in Delhi NCR
Best Makeup Training Institute in Delhi NCR.
best computer institute in delhi NCR
Typing & Shorthand Institute in Delhi NCR