0% found this document useful (0 votes)
36 views1 page

Operator 8

Uploaded by

Hema Malini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Operator 8

Uploaded by

Hema Malini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

One's Complement (~): Right Shift (>>):

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


int main() { int main()
int num = 10; {
int ones_complement = ~num; int num = 20;
printf("One's complement of %d is %d\n", int result = num >> 2;
num, ones_complement); printf("Right shifting %d by 2 positions gives
return 0; %d\n", num, result);
} return 0;
Bitwise AND (&): }
#include <stdio.h>
int main() TRY IT
{ #include <stdio.h>
int num1 = 12, num2 = 25; int main() {
int result = num1 & num2; // One's complement (~)
printf("Bitwise AND of %d and %d is %d\n", int num = 10;
num1, num2, result); int ones_complement = ~num;
return 0; printf("One's complement of %d is %d\n",
} num, ones_complement);
Bitwise OR (|):
#include <stdio.h> // Bitwise AND (&)
int main() int num1 = 12, num2 = 25;
{ int bitwise_and = num1 & num2;
int num1 = 12, num2 = 25; printf("Bitwise AND of %d and %d is %d\n",
int result = num1 | num2; num1, num2, bitwise_and);
printf("Bitwise OR of %d and %d is %d\n",
num1, num2, result); // Bitwise OR (|)
return 0; int bitwise_or = num1 | num2;
} printf("Bitwise OR of %d and %d is %d\n",
num1, num2, bitwise_or);
Bitwise XOR (^):
#include <stdio.h>
// Bitwise XOR (^)
int main()
int bitwise_xor = num1 ^ num2;
{
printf("Bitwise XOR of %d and %d is %d\n",
int num1 = 12, num2 = 25;
num1, num2, bitwise_xor);
int result = num1 ^ num2;
printf("Bitwise XOR of %d and %d is %d\n",
// Left Shift (<<)
num1, num2, result);
int num_shift_left = 5;
return 0;
int left_shift = num_shift_left << 2;
}
printf("Left shifting %d by 2 positions gives
Left Shift (<<): %d\n", num_shift_left, left_shift);
#include <stdio.h>
int main() // Right Shift (>>)
{ int num_shift_right = 20;
int num = 5; int right_shift = num_shift_right >> 2;
int result = num << 2; printf("Right shifting %d by 2 positions gives
printf("Left shifting %d by 2 positions gives %d\n", num_shift_right, right_shift);
%d\n", num, result);
return 0; return 0;
} }

You might also like