Commit 0df225ba by Raul.Leemet

Upload new file

parent 81763daf
Showing with 54 additions and 0 deletions
#include <stdio.h>
void printBits(unsigned int num);
int main() {
unsigned int a = 60; /* 60 = 0011 1100 */
unsigned int b = 13; /* 13 = 0000 1101 */
int c = 0;
printf("%d Value in Bits: ",a);
printBits(a);
printf("\n");
printf("%d Value in Bits: ",b);
printBits(b);
printf("\n");
c = a & b; /* 12 = 0000 1100 */
printf("Line a & b - Value of c is %d\n", c );
printBits(c);
printf("\n");
c = a | b; /* 61 = 0011 1101 */
printf("Line a | b - Value of c is %d\n", c );
printBits(c);
printf("\n");
c = a ^ b; /* 49 = 0011 0001 */
printf("Line a ^ b - Value of c is %d\n", c );
printBits(c);
printf("\n");
c = ~a; /*-61 = 1100 0011 */
printf("Line ~a - Value of c is %d\n", c );
printBits(c);
printf("\n");
c = a << 2; /* 240 = 1111 0000 */
printf("Line a << 2 - Value of c is %d\n", c );
printBits(c);
printf("\n");
c = a >> 2; /* 15 = 0000 1111 */
printf("Line a >> 2 - Value of c is %d\n", c );
printBits(c);
printf("\n");
return 0;
}
void printBits(unsigned int num){
unsigned int size = sizeof(unsigned int);
unsigned int maxPow = 1<<(size*8-1);
// printf("MAX POW : %u\n",maxPow);
int i=0,j;
for(;i<size*8;++i){
// print last bit and shift left.
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