Program to find the XOR of ASCII values of characters in a string | C ++ program to find XOR of ASCII value of characters in string ; Function to find the XOR of ASCII value of characters in string ; store value of first character ; Traverse string to find the XOR ; Return the XOR ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int XorAscii ( string str , int len ) { int ans = int ( str [ 0 ] ) ; for ( int i = 1 ; i < len ; i ++ ) { ans = ( ans ^ ( int ( str [ i ] ) ) ) ; } return ans ; } int main ( ) { string str = " geeksforgeeks " ; int len = str . length ( ) ; cout << XorAscii ( str , len ) << endl ; str = " GfG " ; len = str . length ( ) ; cout << XorAscii ( str , len ) ; return 0 ; }