text: Find uncommon characters of the two strings | Set 2 | Function to print the uncommon characters in the given string in sorted order ; Converting character to ASCII code ; Bit operation ; Converting character to ASCII code ; Bit operation ; XOR operation leaves only uncommon characters in the ans variable ; Driver code
code: function printUncommon ( str1 , str2 ) { var a1 = 0 , a2 = 0 ; for ( var i = 0 ; i < str1 . length ; i ++ ) { var ch = ( str1 [ i ] . charCodeAt ( 0 ) ) - ' ' . charCodeAt ( 0 ) ; a1 = a1 | ( 1 << ch ) ; } for ( var i = 0 ; i < str2 . length ; i ++ ) { var ch = ( str2 [ i ] . charCodeAt ( 0 ) ) - ' ' . charCodeAt ( 0 ) ; a2 = a2 | ( 1 << ch ) ; } var ans = a1 ^ a2 ; var i = 0 ; while ( i < 26 ) { if ( ans % 2 == 1 ) { document . write ( String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ) ; } ans = parseInt ( ans / 2 ) ; i ++ ; } } var str1 = " " ; var str2 = " " ; printUncommon ( str1 , str2 ) ;