C program that takes as input two 8-bit numbers and calculate the AND,OR and XOR logical representations
Posted by Samath
Last Updated: June 13, 2015

Write a C program that takes as input two 8-bit numbers and calculate the AND,OR and XOR logical representations. (Use the bitwise operations)

Code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int num1 [8]; 
	int num2 [8]; 

	printf ("Enter the first binary number of 8-bits: ");
	for (int i=0; i<8; i++)
	{
		scanf ("%d", &num1 [i]);
	}
	
	printf ("Enter the second binary number of 8-bits: ");
	for (int i=0; i<8; i++) 
	{
		scanf ("%d", &num2 [i]);
	}
	
	printf ("\nAND logical representation: ");
	for (int i=0; i<8; i++) 
	{
		printf ("%d", num1 [i] & num2 [i]);
	}
	
	printf ("\nOR logical representation: ");
	for (int i=0; i<8; i++) 
	{
		printf ("%d", num1 [i] | num2 [i]);
	}
	
	printf ("\nXOR logical representation: ");
	for (int i=0; i<8; i++) 
	{
		printf ("%d", num1 [i] ^ num2 [i]);
	}
	
	return 0;
}