हिंदी माध्यम नोट्स
Categories: C Language in hindi
Bitwise Operators : Shift or complement in hindi , बिट वाइज ऑपरेटर : शिफ्ट या कॉम्प्लीमेंट c कंप्यूटर भाषा हिंदी में
बिट वाइज ऑपरेटर : शिफ्ट या कॉम्प्लीमेंट c कंप्यूटर भाषा हिंदी में Bitwise Operators : Shift or complement in hindi :-
इससे पहले article मे,हमने bitwise लॉजिकल operator को पढ़ा |इस article मे , हम bitwise shift और complement operator को पढेगे |
Bitwise shift Operator
इस operator का use किसी बिट पैटर्न मे left या right side मूव करने के लिए किया जाता है |shift operator का syntax >> और << है | इसका syntax है :-
left side : operand << n
right side : operand >>n
यहा पर
operand : कोई integer है जिसके बिट पैटर्न मे shifting होनी वाली है |
n: ये number ऑफ़ bits है जो बिट पैटर्न मे shift होगे |
left bit operator , किसी pattern के सभी bits को left side मे n position तक shift कर देते है |किसी पैटर्न की left most बिट खो सकती है उसके स्थान पर shifted bits आ सकती है |और right side हुई vacant जगह को ‘0’ से filled कर दे जाती है |
right shift operator , किसी pattern के सभी bits को right side मे n position तक shift कर देते है |किसी पैटर्न की right most bit खो सकती है उसके स्थान पर shifted bits आ सकती है |और
अगर integer unsigned होता है तब left side हुई vacant जगह को ‘0’ से filled कर दे जाती है |
अगर integer signed होता है तब vacant जगह की value machine पर निर्भर करती है |
दोनों ही operand और n, constant और variable हो सकती है |लेकिन n की value मे दो limitation हो सकती है :-
1.’n’ की value negative नहीं हो सकती है |
2.’n’ की value किसी integer के भीत पैटर्न मे स्थित bits से ज्यादा नहीं हो सकती है |
उदाहरण के लिए :
a एक unsigned integer है जिसका बिट पैटर्न है 0110 0011 1011 1000
a<<3 : 0101 1101 1100 0000
a>>3 : 0000 1100 0111 0111
a<<3 statement से बिट पैटर्न तीन position left side मे move हो गया |इसलिए बिट पैटर्न के पांच right position पर ‘0’ आ जाता है |
a>>3 statement से बिट पैटर्न 3 position right side मे मूव हो गया|इसलिए बिट पैटर्न के पहले तीन vacant positions पर ‘0’ आ जाता है |
shift operator का use , 2 से multiplication और division के लिए करते है |
उदाहरण -1
#include<stdio.h>
#include<conio.h>
void main()
{
{
int a;
printf(“Enter Value”);
scnaf(“%d”,&a);
b=a<<1;
printf(“Output = %d”,b);
getch();
}
इस उदहारण का आउटपुट होगा :
Enter Value 12
Output 24
बिट पैटर्न मे , 12 : 0000 1100
after shifting , 0001 1000 जो की 24 का बिट pattern है |
अतः इस प्रोग्राम से , हम यूजर द्वारा दिए गये input को 2 से multiply कर सकते है |
उदाहरण -2
#include<stdio.h>
#include<conio.h>
void main()
{
{
int a;
printf(“Enter Value”);
scnaf(“%d”,&a);
b=a>>1;
printf(“Output = %d”,b);
getch();
}
इस उदहारण का आउटपुट होगा :
Enter Value 12
Output 6
बिट पैटर्न मे , 12 : 0000 1100
after shifting , 0000 0110 जो की 6 का बिट pattern है |
अतः इस प्रोग्राम से , हम यूजर द्वारा दिए गये input को 2 से divide कर सकते है |
Bitwise Complement operator
इस operator का use किसी एक operand पर हो सकता है |इसे किसी integer के बिट पैटर्न को complement करने के लिए किया जाता है |इसका मतलब है :-
सभी ‘1’ ,’0′ मे change हो जाये |
और सभी ‘0’ ,’1′ मे change हो जाये |
उदाहरण के लिए :
bit pattern : 0111 1010
Output : 1000 0101
इसका syntax ‘~’ है |
Masking
masking एक प्रोसेस है जिसमे किसी बिट पैटर्न मे से specific bits को extract किया जाता है |masking प्रोसेस मे लॉजिकल operator के अलावा shift operator को भी use कर सकते है |जिस operand पर masking होती उसे mask कहते है |
उदाहरण के लिए
b=a & mask;
b=a | mask;
masking का use :
1. masking का use किसी integer के बिट पैटर्न को decide करने के लिए किया जाता है |
2. किसी बिट पैटर्न के portion को दुसरे variable मे copy करना और पुरने वाले बिट पैटर्न मे vacant place पर ‘0’ place करना |
3. किसी बिट पैटर्न के portion को दुसरे variable मे copy करना और पुरने वाले बिट पैटर्न मे vacant place पर ‘1’ place करना |
4.किसी बिट पैटर्न के portion को दुसरे variable मे copy करना और पुरने वाले बिट पैटर्न मे बचेर हुए बिट को invert करना |
उदाहरण के लिए :
दो इनपुट्स है (i) 101001 (ii) 001100 |इन input से 001000 बिट पैटर्न चाहिए |ये तभी हो सकता है जब दोनों input का OR operation हो |इसका code है:-
दो इनपुट्स है (i) 101001 (ii) 001100 |इन input से 001000 बिट पैटर्न चाहिए |ये तभी हो सकता है जब दोनों input का OR operation हो |इसका code है:-
#include<stdio.h>
#include<conio.h>
void main()
{
{
int a,b,c;
printf(“Enter Value”);
scnaf(“%d”,&a &b);
c=a|b;
c=a|b;
printf(“Output = %d”,c);
getch();
}
इस उदाहरण का आउटपुट होगा : 001000इस प्रकार दो या दो से अधिक bitwise operator को use करके ,प्रोग्रामर desired आउटपुट प्राप्त कर सकता है |इस प्रोसेस को Masking कहते है |
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
4 weeks ago
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
4 weeks ago
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
4 weeks ago
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
4 weeks ago
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
1 month ago
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
1 month ago