Bitwise OR Operator : ये Operator Use करके हम दो Identifier के Bits पर OR Masking की प्रक्रिया को Apply करते हैं। OR Masking में दोनों Identifiers के Bits आपस में OR Form में Compare होते हैं। यदि दोनों Identifiers में से किसी एक भी Identifier में समान Position पर Bit का मान 1 हो यानी Bit True हो तो Resultant Bit भी True होता है, अन्यथा Resultant Bit False हो जाता है।
OR Masking को हम निम्नानुसार समझ सकते हैं, जहां दो Variables में 19 व 21 मान Stored है:
int firstValue = 19; //Binary : 10011 int secondValue = 21; //Binary : 10101 int resultValue;
इन दोनों Identifiers पर OR Masking की प्रक्रिया को Apply करने पर निम्नानुसार Operation Perform होते हैं:
result = firstValue | secondValue; firstValue’s Binary : 10011 // Decimal Value = 19 secondValue’s Binary : 10101 // Decimal Value = 21 --------------------------------------------- resultValue’s Binary : 10111 // Decimal Value = 23 ---------------------------------------------
OR Masking में Identifier के Bits पर निम्नानुसार Table के अनुसार पर प्रक्रिया होती है, जिसमें दोनों Identifiers के समान Position के दोनों Bits का आपस में Comparison होता है और तीसरे Identifier में समान Position पर ही Resultant Bit Return होता है।
Bitwise OR Operator का प्रयोग किसी Bit Pattern में स्थित किसी खास Bit को ON करने के लिए किया जाता है। जब हमें किसी अमुक Bit को किसी Bit-Pattern में ON करना होता है, तब हमें एक और Bit-Pattern की जरूरत होती है। इस दूसरे Bit-Pattern को OR Mask Bit Pattern कहते हैं। इस OR Mask में हमें केवल उसी Bit का मान 1 रखना होता है, जिसे हम हमारे प्रथम Bit-Pattern में ON करना चाहते हैं।
चलिए, एक उदाहरण द्वारा OR Masking की प्रक्रिया को समझते हैं। मानलो कि हम Bit-Pattern 10100110 (Value = 150) की चौथी Bit को On करना चाहते हैं। इस जरूरत को पूरा करने के लिए हमें OR Mask के रूप में Bit-Pattern 00001000 को Use करना होगा। जब हमें इस पर OR Masking की प्रक्रिया करनी हो, तो ये प्रक्रिया निम्नानुसार होगी:
result = firstValue | secondValue; firstValue’s Binary : 10010110 // Decimal Value = 150 secondValue’s Binary : 00001000 ------------------------------------------------------ resultValue’s Binary : 10011110 // Decimal Value = 158 ------------------------------------------------------
Resultant मान में हम देख सकते हैं, कि इसके केवल चौथे Bit का मान ही 0 से 1 हुआ है। चूंकि चौथे Bit-Position का मान 8 होता है, इसलिए Resultant मान 158 प्राप्त हो रहा है, जो कि Original मान 150 से केवल 8 ही ज्यादा है। इस समस्या का Program निम्नानुसार है:
Program #include <stdio.h> #include <conio.h> main() { int x = 150, j; clrscr(); printf("\n Value of x is %d ", x); j = x | 8; printf("\n Forth Bit of value %d is Now On", x); printf("\n Now the Value of x is %d " , j); getch(); } Output: Value of x is 150 Forth Bit of value 150 is Now On Now the Value of x is 158
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook C Programming Language in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी।
C Programming Language in Hindi | Page: 477 + 265 | Format: PDF