Dark Mode Logo (Optional)

Dark Mode Logo (Optional)

Bitwise XOR (Exclusive OR) Operator (^)




ये 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 है |

इन दोनों Identifiers पर XOR Masking की प्रक्रिया को Apply कर निम्नानुसार Operation Perform होते है |

XOR Masking में निम्नानुसार Table के अनुसार Bits पर प्रक्रिया होती है , जिसमें दोनों Identifiers के सामने Position के दोनों Bits का आपस में Comparison होता है और समान Position पर ही Resultant Bit Return होता है |

इस 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

You may like these posts:

No comments:

Post a Comment