Commit 9796a1c2 by antsim

pr10

parent d5ad0e51
Showing with 92 additions and 0 deletions
#include <stdio.h>
#include <string.h>
void printBits(unsigned int num);
int main()
{
unsigned int a;
unsigned int b;
int c = 0;
int nihe=0;
int menu;
printf("Enter option:\n");
printf("1. Conjunction\n");
printf("2. Disjunction\n");
printf("3. Nihutamine vasakule\n");
printf("3. Nihtamine paremale\n");
scanf("%d", &menu);
switch(menu)
{
case 1:
c=a&b;
printf("Enter the first numer a: ");
scanf("%u", &a);
printf("Enter the second number b: ");
scanf("%u", &b);
printf("%d Value in Bits: ",a);
printBits(a);
printf("\n");
printf("%d Value in Bits: ",b);
printBits(b);
printf("Line a & b - Value of c is %d\n", c );
printBits(c);
break;
case 2:
c=a|b;
printf("Enter the first numer a: ");
scanf("%u", &a);
printf("Enter the second number b: ");
scanf("%u", &b);
printf("%d Value in Bits: ",a);
printBits(a);
printf("\n");
printf("%d Value in Bits: ",b);
printBits(b);
printf("Line a & b - Value of c is %d\n", c );
printBits(c);
printf("\n");
break;
case 3:
printf("Sisestage nihe vaartus:");
scanf("%d", &nihe);
c=a<<nihe;
printf("Line a << %d - Value of c is %d\n", nihe, c );
printBits(c);
printf("\n");
break;
case 4:
printf("Sisestage nihe vaartus:");
scanf("%d", &nihe);
c=a>>nihe;
printf("Line a >> %d - Value of c is %d\n", nihe, c );
printBits(c);
printf("\n");
break;
default:
printf("You have entered an invalid option\n");
}
return 0;
}
void printBits(unsigned int num){
unsigned int size = sizeof(unsigned int);
unsigned int maxPow = 1<<(size*8-1);
int i=0;
for(;i<size*8;++i){
printf("%u ",!!(num&maxPow));
num = num<<1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment