forked from randerson112358/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitwiseOperations.c
48 lines (37 loc) · 894 Bytes
/
bitwiseOperations.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//Description: This program performs a few bitwise operations
// bitwise and = &
// bitwise or = |
// bitwise xor = ^
//library
#include <stdio.h>
int main(){
//variables to do the bitwise operations on
int x = 13; // 13 = 1101 in binary
int y = 27; // 27 = 11011 in binary
int z = 10; // 10 = 1010 in binary
/*
Exclusive OR AKA XOR
x = 13 = 01101
xor y = 27 = 11011
------------------
1 0 1 1 0 = 2^4 + 2^2 + 2^1 = 16 + 4 + 2 = 22
*/
printf("XOR x^y = %d \n", x^y);
/*
Bitwise AND
x = 13 = 1101
and z = 10 = 1010
-----------------
1 0 0 0 = 2^3 = 8
*/
printf("AND x&z = %d \n", x&z);
/*
Bitwise OR
y = 27 = 11011
or z = 10 = 01010
-----------------
1 1 0 1 1 = 2^4 + 2^3 + 2^1 + 2^0 = 16 + 8 + 2 + 1 = 27
*/
printf("OR y|z = %d \n", y|z);
return 0;
}