I am having some problems with writing a program for adding, subtracting, multiplying and dividing binary. the major problem i am having is being able to restricting the program to give output of 1s and 0s (the binary part) and also it needs to be able to manipulate the binary if it as decimals in them such as 101.1 or 1.0101. Below is a program i have found online during my research but i dont fully understand how it works as yet to implement my own nor does it capable of computing binary with decimals in them. I do not want to use arrays as it limits the maximum output depending on the bits you put aside to do these calculations.
Looking forward to some potential ideas.
#include<stdio.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;
}