Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #include<stdlib.h>
- unsigned int NOR(unsigned int,unsigned int);
- unsigned int X_NOR(unsigned int,unsigned int);
- unsigned int NAND(unsigned int,unsigned int);
- int main(void)
- {
- unsigned int a,b;
- int choice;
- do{
- printf("\nWelcome to Logic Gates...\n");
- printf("1)Nor gate\n");
- printf("2)X-Nor gate\n");
- printf("3)Nand gate\n");
- printf("4)Exit\n\n");
- printf("Enter a and b (Two Inputs for Logic Gate) \n");
- scanf("%u %u",&a,&b);
- printf("\nNow Choose Any Logic Gate\n");
- scanf("%d",&choice);
- switch(choice){
- case 1 :
- printf("\nNOR gate :\n %u NOR %u --> %u\n",a,b,NOR(a,b));
- break;
- case 2 :
- printf("\nX-NOR gate :\n %u X-NOR %u --> %u\n",a,b,X_NOR(a,b));
- break;
- case 3 :
- printf("\nNAND gate :\n %u NAND %u --> %u\n",a,b,NAND(a,b));
- break;
- case 4 : exit(0);
- break;
- default : fputs("Error Wrong Choice\n",stderr);
- }
- }while(choice < 4);
- return 0;
- }
- unsigned int NOR(unsigned int a,unsigned int b)
- {
- return ( (~(a | b)) & (((int)pow(2,floor(log2( (a > b) ? ((a == 0) ? 1 : a) : ((b == 0) ? 1 : b) )) + 1) ) - 1) );
- }
- unsigned int X_NOR(unsigned int a,unsigned int b)
- {
- return ( (~(a ^ b)) & (((int)pow(2,floor(log2( (a > b) ? ((a == 0) ? 1 : a) : ((b == 0) ? 1 : b) )) + 1) ) - 1) );
- }
- unsigned int NAND(unsigned int a,unsigned int b)
- {
- return ( (~(a & b)) & (((int)pow(2,floor(log2( (a > b) ? ((a == 0) ? 1 : a) : ((b == 0) ? 1 : b) )) + 1) ) - 1));
- }
Add Comment
Please, Sign In to add comment