WhatsApp Group Join Now
Telegram Join Join Now

C++ : Bitwise Operator ( Part-1 ) in hindi , what is Bitwise Operators in c++ language

what is Bitwise Operators in c++ language , C++ : Bitwise Operator ( Part-1 ) in hindi :-
इससे पहले एक article मे c++ मे उपस्थित केवल arithmatic operator or relation operator or logical operator को discuss किया है | अब इस article मे bitwise operator को discuss करेगे |
c++ मे operators main bitwise operator का मुख्य भूमिका है :-
arithmetic operator
इस category मे पांच arithmatic operators है जिसमे addition(+),subtraction(-) , multiplication(*) , division(/), और modulas(%) है | इस सभी operator को basic arithmatic operation मे use किया जाता है | इन सभी को हम पहले अच्छी तरह से discuss कर चुके है |
2. Relation operator
जब किसी प्रोग्राम मे दो या दो से अधिक संख्याओं में तुलना करने के काम में लिया जाता है तब इस operator को उपयोग किया जाता है | इस श्रेणी मे पांच Relation operator (सम्बन्ध ऑपरेटर) है | जब किसी expression मे Relation operator को उपयोग किया जाता है तब इसे Relation expression कहते है | सभी Relation expression की value Boolean होती है | अथात इसकी true और false value होती है | इसमें larger than (>) , smaller than(<) , larger and equal than (>=) और smaller and equal than (<=) होता है | Equal than (==)operator भी Relation operator होता है |
3. Logical Operator
ये operator का दो या दो से अधिक relation expressions को जोड़ने के लिए किया जाता है | इसमें logical and operator (&&) , logical Or operator (||) ओए logical or होता है |
Bitwise operator
Bitwise operator का use, bit level operation के लिए किया जाता है | इसके लिए bit operand होते है इसका मतलब है की bitwise operator का use , bits पर होता है | ये operator operand को bits मे convert कर देता है | उसके बाद operation perform होता है |bits पर Mathematical operator को perform करने से speed बढ़ जाती है |
C++ मे bitwise operator को पांच भागो मे divind किया गया है :-
1. Bitwise OR
जब किसी दो bits pattern के बीच OR operation perform किया जाता है | तब इस Bitwise OR का use किया जाता है | इसका syntax “|” है | अगर दोनो bits मे कोई एक बिट “true” होता है तब इस expression का आउटपुट भी ‘1’ होगा |
इस operation मे सबसे पहले number को बिट पैटर्न मे convert कर दिया जाता है | फिर उस पर bitwise OR operation परफोर्म किया जाता है |
इसका truth table होता है |
अगर bit a = 1 or int b= 1 than output 1 होता है |
अगर bit a = 1 or int b= 0 than output 1 होता है |
अगर bit a = 0 or int b= 1 than output 1 होता है |
अगर bit a = 0 or int b= 0 than output 0 होता है |
इसका उदाहरण होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,d;
cout<<“Enter First Value :”<<endl;
cin>>a;
cout<<“Enter Second Value :”<<endl;
cin>>b;
d=a|b;
cout<<“OR Operation Output:”<<d<,endl;
getch();
}
इस उदाहरण मे दो variable को declare किया जाता है | जिसको variable ‘a’ और ‘b’ मे assign कर दिया जाता है |
और d=a|b expression के आउटपुट को variable d मे assign कर देते है | इस variable का type integer है |
BIT Pattern of first value 12 : 01100
BIT Pattern of first value 23 : 10111
after OR Operation : 11111 ( Equal to decimal number : 31)
इसका आउटपुट होगा
Enter First Value : 12
Enter Second Value : 23
OR Operation Output: 31
2. Bitwise AND
जब किसी दो bits pattern के बीच AND operation perfrom किया जाता है | तब इस Bitwise AND का use किया जाता है | इसका syntax “&” है | अगर दोनो bits “true” होता है तब इस expression का आउटपुट भी ‘1’ होगा |
इस operation मे सबसे पहले number को बिट पैटर्न मे convert कर दिया जाता है | फिर उस पर bitwise and operation परफोर्म किया जाता है |
इसका truth table होता है |
अगर bit a = 1 or int b= 1 than output 1 होता है |
अगर bit a = 1 or int b= 0 than output 0 होता है |
अगर bit a = 0 or int b= 1 than output होता है |
अगर bit a = 0 or int b= 0 than output 0 होता है |
इसका उदाहरण होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,d;
cout<<“Enter First Value :”<<endl;
cin>>a;
cout<<“Enter Second Value :”<<endl;
cin>>b;
d=a&b;
cout<<“AND Operation Output:”<<d<,endl;
getch();
}
इस उदाहरण मे दो variable को declare किया जाता है | जिसको variable ‘a’ और ‘b’ मे assign कर दिया जाता है |
और d=a|b expression के आउटपुट को variable d मे assign कर देते है | इस variable का type integer है |
BIT Pattern of first value 34 : 100010
BIT Pattern of first value 54 : 110110
after AND Operation : 100010 ( Equal to decimal number : 34)
इसका आउटपुट होगा
Enter First Value : 34
Enter Second Value : 54
AND Operation Output: 34
3. Bitwise Xor
जब किसी दो bits pattern के बीच XOR operation perfrom किया जाता है | तब इस Bitwise XOR का use किया जाता है | इसका syntax “^” है | अगर दोनो bits सामान होती है तब ही इस expression का आउटपुट भी ‘1’ होगा |
इस operation मे सबसे पहले number को बिट पैटर्न मे convert कर दिया जाता है | फिर उस पर bitwise XOR operation परफोर्म किया जाता है | इस operator का use कई सारे operation मे किया जाता है |
इसका truth table होता है |
अगर input a = 1 or int b= 1 than output 1 होता है |
अगर input a = 1 or int b= 0 than output 0 होता है |
अगर input a = 0 or int b= 1 than output 0 होता है |
अगर input a = 0 or int b= 0 than output 1 होता है |
इसका उदाहरण होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,d;
cout<<“Enter First Value :”<<endl;
cin>>a;
cout<<“Enter Second Value :”<<endl;
cin>>b;
d=a&b;
cout<<“AND Operation Output:”<<d<,endl;
getch();
}
इस उदाहरण मे दो variable को declare किया जाता है | जिसको variable ‘a’ और ‘b’ मे assign कर दिया जाता है |
और d=a^b expression के आउटपुट को variable d मे assign कर देते है | इस variable का type integer है |
BIT Pattern of first value 67 : 1000011
BIT Pattern of first value 98 : 1100010
after XOR Operation : 1011110( Equal to decimal number : 94)
इसका आउटपुट होगा
Enter First Value : 67
Enter Second Value : 98
AND Operation Output: 94
इस article मे , उन bit-wise operator को discuss किया है जो की लॉजिकल operator के सामान होते है उनमे केवल एक अंतर होता है की लॉजिकल operator Relation expression के output पर apply होता है और bitwise operator bits पर अप्लाई होता है | इसके आगे के article मे shift operator को discuss करेगे |