Skip to content

šŸš„šŸš„Bitwise : sueing my haters bitwisešŸŒ

Notifications You must be signed in to change notification settings

Abhishek-Singh296/Bitwise-Operation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Ā 

History

13 Commits
Ā 
Ā 
Ā 
Ā 

Repository files navigation

Bitwise-Operation

In C, the following 6 operators are bitwise operators (also known as bit operators as they work at the bit-level). They are used to perform bitwise operations in C.

  • 1.The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.
  • 2.The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1.
  • 3.The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.
  • 4.The << (left shift) in C or C++ takes two numbers, the left shifts the bits of the first operand, and the second operand decides the number of places to shift.
  • 5.The >> (right shift) in C or C++ takes two numbers, right shifts the bits of the first operand, and the second operand decides the number of places to shift.
  • 6.The __~ (bitwise NOT)__ in C or C++ takes one number and inverts all bits of it.

bitwose-ope


Code I

//Bitwise_operation
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
		//To count the number of 1's
	int num,count=0;
	printf("Enter the number:\n");
	scanf("%d",&num);
	
	do{
		if(num&1){
		count++;
		}
		num=num>>1;
		
	}while(num!=0);
	printf("Number of 1's is:%d",count);
	//To check number is even or odd
	if(num&0){
		printf("Number is odd");
	}
	else {
		printf("Number is even");
	}
	
	return 0;
}

Output I

Screenshot 2023-04-11 154745

Code II

//Bitwise_main
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	int x,y,z;
	char bitwise;
	printf("Enter the Bitwise operator:");
	scanf("%c",&bitwise);
	printf("Enter the first number:\n");
	scanf("%d",&x);
	printf("Enter the second number:\n");
	scanf("%d",&y);
	


	
	switch (bitwise)
	{
		case '&':
			z=x&y;
			printf("Bitwise AND of x & y is:%d\n",z);
			break;
		case '|':
			z=x|y;
			printf("Bitwise OR of x & y is:%d\n",z);
			break;
		case '^':
			z=x^y;
			printf("Bitwise XOR of x & y is:%d\n",z);
			break;
		case '~':
			z=x~y;
			printf("Bitwise NOT of x & y is:%d\n",z);
			break;
		default :
			printf("Enter a Valid Bitwise Operator(&/|/^/~)");
	}
	
	
	return 0;
}

Output

Screenshot 2023-04-11 154314

About

šŸš„šŸš„Bitwise : sueing my haters bitwisešŸŒ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages