Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main(){
- int *stop,decNum1=0,decNum2=0,result=0,ip_base=2,flag=0,i=0,binLength=0,temp=0,opResult[15];
- char num1[15],num2[15];
- puts("\n");
- do{
- printf("enter two binary numbers of same length(<15):\n");
- printf(" enter 1st binary number: ");
- fgets(num1,15,stdin);
- binLength=strlen(num1);
- decNum1=strtol(num1,&stop,ip_base);// decNum1 is the dec equivalent of binary input num1(a string)
- printf(" enter 2nd binary number: ");
- fgets(num2,15,stdin);
- decNum2=strtol(num2,&stop,ip_base);
- result=decNum1^decNum2; // dec equivalent of XOR addition
- printf("\n xor output:\n\n ");
- for(i;i<binLength;i++){ // converts the dec back to binary
- temp = result%2;
- result=result/2;
- opResult[i]=temp;
- }
- for(i=binLength-1;i>=0;i--){ // prints the result in the correct order
- printf("%d",opResult[i]);
- }
- printf("\n\n repeat? 1.yes 0.no\n ");
- scanf("%d",&flag);
- while((i=getchar())!='\n'){}
- i=0;
- }while(flag==1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement