Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. STRING1 : 011011110011000
  2.  
  3. STRING2 : 011001000001000
  4.  
  5. EXPECTED OUTPUT : 000010110010000
  6.  
  7. for(int i = 0; i<15; i++)
  8. {
  9. final_key[i] = STRING1[i] ^ STRING2[i];
  10. cout<<" XOR = "<<final_key[i];
  11. }
  12.  
  13. final_key[i] = ((STRING1[i]-'0') ^ (STRING2[i]-'0')) + '0';
  14.  
  15. #incude <string>
  16. #incude <bitset>
  17. #incude <iostream>
  18.  
  19. int main()
  20. {
  21. std::string s1 = "010101010101010101";
  22. std::string s2 = "101010101000001111";
  23.  
  24. auto result = std::bitset<32>(s1) ^ std::bitset<32>(s2);
  25. std::cout << result << std::endl;
  26. }
  27.  
  28. char result = std::abs(a - b) + '0';
  29.  
  30. string strings_xor(string s, string t) {
  31.  
  32. string res = "";
  33. for(int i = 0; i < s.size(); i++) {
  34. if(s[i] == t[i])
  35. res += '0';
  36. else
  37. res += '1';
  38. }
  39.  
  40. return res;
  41.  
  42. string s1="011011110011000";
  43. string s2="011001000001000";
  44. char final_key[15];
  45. for(int i = 0; i<15; i++)
  46. {
  47. final_key[i] = (s1[i] ^ s2[i])+'0'; //paranthesis is important
  48. cout<<final_key[i];
  49. }
  50.  
  51. final_key[i]=(s1[i]!=s2[i]?'1':'0');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement