Bitwise Operators in Strings

Could Bitwise operators used to find the unique character in a string ? If Yes, Explain How in Strings Bitwise Operators are used

Hi @dhruvtrehan45
Yes you can use bitwise operator in on strings as well character by character. Like for example if you want to convert upper case to lower or vice versa then :

In ASCII codes, character ‘A’ is integer 65 = (0100 0001), while character ‘a’ is integer 97 = (0110 0001). Similarly, character ‘D’ is integer 68 = (0100 0100), while character ‘d’ is integer 100 = (0110 0100). As we can see, only sixth least significant bit is different in ASCII code of ‘A’ and ‘a’. Similar behavior can be seen in ASCII code of ‘D’ and ‘d’. Therefore, we need to toggle this bit for toggling case. The integer with 6th LSB as 1 is 32 (0010 0000). Therefore, bitwise XORing of a character with 32 will toggle the 6th LSB of character and hence, will toggle its case. If character is upper case, it will be converted to lower case and vice versa.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.