{"id":20483,"date":"2021-09-13T14:51:27","date_gmt":"2021-09-13T09:21:27","guid":{"rendered":"https:\/\/python-programs.com\/?p=20483"},"modified":"2021-11-22T18:36:20","modified_gmt":"2021-11-22T13:06:20","slug":"python-program-to-find-xor-of-two-numbers-without-using-xor-operator","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-xor-of-two-numbers-without-using-xor-operator\/","title":{"rendered":"Python Program to Find XOR of Two Numbers Without Using XOR operator"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find Position of Rightmost Set Bit<\/a><\/p>\n

Give two numbers the task is to find the XOR result of the given two numbers in Python.<\/p>\n

Bitwise & Operator:<\/strong><\/p>\n

If both bits are 1, sets each bit to 1.<\/p>\n

Bitwise or (|) operator:<\/strong><\/p>\n

If one of two bits is 1, sets each bit to 1.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given First Number = 4\r\nGiven Second Number = 2<\/pre>\n

Output:<\/strong><\/p>\n

The XOR result of the given first and second numbers{ 4 , 2 } = 6<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given First Number = 7\r\nGiven Second Number = 9<\/pre>\n

Output:<\/strong><\/p>\n

The XOR result of the given first and second numbers{ 7 , 9 } = 14<\/pre>\n

Program to Find XOR of Two Numbers Without Using XOR operator in Python<\/h2>\n

Below are the ways to find the XOR result of the given two numbers in Python:<\/p>\n