Bitwise XOR Operator in C Language

Bitwise XOR Operator in C : ये 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 कर रहे हैं, जिसमें दो Variables में मान 19 21 Stored हैं:

int firstValue = 19;	//Binary : 10011
int secondValue = 21;	//Binary : 10101 
int resultValue;

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

result = firstValue ^ secondValue;

firstValue’s Binary	: 10011		// Decimal Value = 19
secondValue’s Binary	: 10101		// Decimal Value = 21	
--------------------------------------------------
resultValue’s Binary 	: 00110		// Decimal Value = 6
--------------------------------------------------

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

Bitwise XOR Operator in C Language

इस 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;
	clrscr();
	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		//	Bit-Pattern : 00110010
Value of k is 10		//	Bit-Pattern : 00001010
k = 10 is Masking the value of x = 50	
After XOR Masking the Value of x is 56		// Resultant 	: 00111000
k = 10 is Masking the Changed Value of x = 56 again
Now the Value of x is changed again to 50	// Resultant 	: 00110010

C Programming Language in Hindi - BccFalna.com ये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook  C Programming Language in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी। 

C Programming Language in Hindi | Page: 477 + 265 | Format: PDF

BUY NOW GET DEMO REVIEWS