Toggle String using c#

Input: ArUnAshrItH

Output: aRuNaSHRiTh

Just need to toggle the string on the input.

I will explain the core concept how its converting the case.

inputArray[i] = (char)((int)(inputArray[i]) ^ (1 << 5));

Breakup this line into multiple line to explain.

(1 << 5) : In this line of code its shifting an array of binary value of ONE into 5 times.

Binary equealent to ONE is 00000001

After shifting the characters 00100000

Ref this stack overflow https://stackoverflow.com/questions/2007526/what-does-the-operator-mean-in-c

The outcome of (1 << 5) always it will be 32.

Now, we have to convert the char into ascii value .

(int)(inputArray[i]) : This line of code is doing this job.

After this, we have to do OR binary operation for two values. The answer will be the Ascii value of toggle character, so after that we can convert into char and update in the array.

For Example lets take a character “A”

Step1: (1 << 5) Result of this line is 32, binary equivalent for this line is: 00100000

Step2: Let’s take “A” . 65 is the equivalent ASCII value for “A” character. convert this into binary 01000001

Step3: Step2 ^ Step1

Step4: After getting the binary value of 97 we need to convert back into char value.

(char) : this convert will convert the int value into char.

Step5: Replace the value in the appropriate array position.

Step6: So, the Final out come of the expression is “a” (97)