+ 1

How to use this operator ^. Example: c[0] ^ 32;What this mean??

Ex. string str; public void readdata() { Console.Write("Enter a String : "); str = Console.In.ReadLine(); } public void abbre() { char[] c, result; int j = 0; c = new char[str.Length]; result = new char[str.Length]; c = str.ToCharArray(); result[j++] = (char)((int)c[0] ^ 32); result[j++] = '.';

6th Sep 2017, 3:20 PM
Lin N
Lin N - avatar
4 Réponses
+ 3
Short answer It toggles the upper/lower case letter Long answer The ^ operator was used to perform XOR bitwse operation. As you can see at this line the character was cast into integer and back to character again after apply XOR with 32:- (char)((int)c[0] ^ 32) Let's say you got a character 'C', its binary representation is 100 0011. 100 0011 ^ 010 0000 = 110 0011. which represents the character 'c'. Take note that if you apply the operation again you'll get back the original letter. P/S: You can refer to the ASCII table to find out the number representation of characters. (e.g. A = 65, a = 97 etc.) 💡 Demo https://code.sololearn.com/cPeyh9v4EjtN/?ref=app
6th Sep 2017, 5:31 PM
Zephyr Koo
Zephyr Koo - avatar
+ 2
I don't know anything about C# But "^" is usually the "power of" operator. meaning 3^3 is the same as 3 * 3 * 3 which equals 27
6th Sep 2017, 3:29 PM
Timothy Edge
Timothy Edge - avatar
+ 1
Thank u very much. Complete answer Zephyr Koo.
6th Sep 2017, 11:41 PM
Lin N
Lin N - avatar
0
Thank u Timothy Edge.
6th Sep 2017, 3:33 PM
Lin N
Lin N - avatar