Bitwise XOR (Exclusive OR) Operator (^)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKgpAv2cHkHzHy1TO4Sche3_UUgTtmcL_bmVqXmu_9VdHAUjg0TPLmRE9Ptn51ru8jyq1nzUEgVbeXtsjOrlbgaiUvquu-4yGvDYZ8Ws0rP9S0-EKeFFWfD6OUHbITtEBY5UMPohuCY8w/w640-h480/Bitwise+XOR.jpg)
ये Operator
Use करके हम दो Identifier के Bits पर XOR Masking की प्रक्रिया को Apply करते है | XOR Masking में दो Identifiers के Bits आपस
में XOR Form में Compare होते है |
यदि
दोनों Identifiers
में किसी एक भी Identifier में समान Position
पर Bit का मान 1 हो यानी Bit True हो
तो Resultant Bit भी True होता है ,
लेकिन यदि दोनों ही Identifiers में समान Position पर समान Bit हो , तो Resultant Bit False हो जाता है | XOR
Masking को समझने के लिए हम उदाहरण को Use कर
रहे है , जिसमें दो Variable में मान 19 व 21 Stored है |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEingbvYbdXJ-iSgDvMZczrSMFDwNC6in3QKY4xqRDnyCNfsxSwvSSaAS3fyxF4v5VatSYUltClXbO2ILstsPa9L4UVJJXAMObfsn4J1p5fMdC1waZf1s7AwutosdJGzXLVUBxzdaF1DJcU/w640-h200/1.jpg)
इन दोनों Identifiers
पर XOR Masking की प्रक्रिया को Apply कर निम्नानुसार Operation Perform होते है |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMtDFHH1jDzx0nZwhfbnKBp9HwD8Rmc20J2J7rkTAQwSTgHtXgfRFT1ZDycGlSSxO2BYsdMSeWx0j82fvdcJ7PgRVk2A-CpONLGHRJfyNLBUXvTVq0rmNsPIBdlXLeHPw1e4IEwwGrHGU/w640-h196/2.jpg)
XOR Masking में निम्नानुसार Table के अनुसार Bits पर प्रक्रिया होती है , जिसमें दोनों Identifiers के
सामने Position के दोनों Bits का आपस
में Comparison होता है और समान Position पर ही Resultant Bit Return होता है |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsE8peQZLZEeF0GbMC0_tobsjHzy1QT3JSoNwil68K4cVdNpplvBwTGk4V3GSsGqVJFZz581n_sChVrakdD7Rq0cblR_NvOsTtn8_Ijlmo2MpRnFZDQ0Qt6Z4d8Jopofm75M1tkqqsX_g/w640-h170/3.jpg)
इस Operator
का प्रयोग करके हम किसी Identifier की Bits को Toggle तरीके से बार – बार On/ Off कर सकते है | यानी
जब हमें किसी Identifier के Bits को Toggle तरीके से On/Off करना
होता है , तब हम इस Bitwise Operator का प्रयोग करते है |
इस
Operator
को हम निम्न Program के अनुसार Use कर सकते है |
Program
#include <stdio.h>
main()
{
int x = 50, k=10;
printf("\n Value of x is %d ", x);
printf("\n\n Value of k is %d ", k);
printf("\n\n k = %d is Masking the value of x = %d \n", k, x);
x = x ^ k;
printf("\n After XOR Masking the Value of x is %d \n" , x);
printf("\n k = %d is Masking the Changed Value of x = %d again", k, x);
x = x ^ k;
printf("\n\n Now the Value of x is changed again to %d " , x);
}
Output
Value of x is 50
Value of k is 10
k = 10 is Masking the value of x = 50
After XOR Masking the Value of x is 56
k = 10 is Masking the Changed Value of x = 56 again
Now the Value of x is changed again to 50
No comments