Wednesday, January 21, 2026
HomeLanguagesTensorflow bitwise.bitwise_xor() method – Python

Tensorflow bitwise.bitwise_xor() method – Python

Tensorflow bitwise.bitwise_xor() method performs the bitwise_xor operation and the result will set those bits, that are different in a and b. The operation is done on the representation of a and b. This method belongs to bitwise module.

Syntax: tf.bitwise.bitwise_xor(a, b, name=None)

Arguments

  • a: This must be a Tensor.It should be from the one of the following types: int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  • b: This should also be a Tensor, Type same as a.
  • name: This is optional parameter and this is the name of the operation.

Return: It returns a Tensor having the same type as a and b.

Let’s see this concept with the help of few examples:
Example 1:




# Importing the Tensorflow library 
import tensorflow as tf 
  
# A constant a and b 
a = tf.constant(43, dtype = tf.int32) 
b = tf.constant(5, dtype = tf.int32) 
  
# Applying the bitwise_xor function 
# storing the result in 'c' 
c = tf.bitwise.bitwise_xor(a, b) 
  
# Initiating a Tensorflow session 
with tf.Session() as sess:
    print("Input 1", a)
    print(sess.run(a))
  
    print("Input 2", b)
    print(sess.run(b))
  
    print("Output: ", c)
    print(sess.run(c))


Output:

Input 1 Tensor("Const_36:0", shape=(), dtype=int32)
43
Input 2 Tensor("Const_37:0", shape=(), dtype=int32)
5
Output:  Tensor("BitwiseXor_4:0", shape=(), dtype=int32)
46

Example 2:




# Importing the Tensorflow library 
import tensorflow as tf 
  
# A constant vector of size 2 
a = tf.constant([10, 6], dtype = tf.int32) 
b = tf.constant([12, 5], dtype = tf.int32) 
  
# Applying the bitwise_xor function 
# storing the result in 'c' 
c = tf.bitwise.bitwise_xor(a, b) 
  
# Initiating a Tensorflow session 
with tf.Session() as sess:
    print("Input 1", a)
    print(sess.run(a))
    print("Input 2", b)
    print(sess.run(b))
    print("Output: ", c)
    print(sess.run(c))


Output:

Input 1 Tensor("Const_34:0", shape=(2, ), dtype=int32)
[10  6]
Input 2 Tensor("Const_35:0", shape=(2, ), dtype=int32)
[12  5]
Output:  Tensor("BitwiseXor_3:0", shape=(2, ), dtype=int32)
[6 3]
Last Updated :
26 May, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS