initial import
[staff/goc4/2018bti7061.git] / c-3-libraries / examples / c-lowlevel / bitwiseoperations.c
1 #include <stdio.h>
2
3 int main(){
4 puts("One's complement (negate each bit)");
5
6 int number1 = 0x1;
7 int number2 = ~number1; // One's complement to number1
8
9 printf("n1= %X and n2=%X \n",number1,number2);
10
11 number1 = 0xF0FF00;
12 number2 = ~number1; // One's complement to number1
13
14 printf("n1= %X and n2=%X \n",number1,number2);
15
16 puts("AND (= &) operator");
17
18 int n1 = 0xFF11;
19 int n2 = 0x5599;
20
21 int n3 = n1 & n2;
22
23 printf("%X AND %X = %X \n",n1,n2,n3);
24
25 puts("OR (= |) operator");
26
27 int n4 = n1 | n2;
28
29 printf("%X OR %X = %X \n",n1,n2,n4);
30
31
32 puts("XOR (= ^) operator");
33
34
35 int n5 = n1 ^ n2;
36
37 printf("%X XOR %X = %X \n",n1,n2,n5);
38
39
40 /* Output:
41 One's complement (negate each bit)
42 n1= 1 and n2=FFFFFFFE
43 n1= F0FF00 and n2=FF0F00FF
44 AND (= &) operator
45 FF11 AND 5599 = 5511
46 OR (= |) operator
47 FF11 OR 5599 = FF99
48 XOR (= ^) operator
49 FF11 XOR 5599 = AA88
50 */
51
52
53 }