keras 位运算
import tensorflow as tf
x=1011
y=1001
# 按位与
a=tf.bitwise.bitwise_and(x,y,name=None)
# 按位或
b=tf.bitwise.bitwise_or(x,y,name=None)
# 按位异或
c=tf.bitwise.bitwise_xor(x,y,name=None)
# 翻转所有位元素
d=tf.bitwise.invert(x,name=None)
# 按位左移函数
e=tf.bitwise.left_shift(x,y,name=None)
# 按位右移函数
f=tf.bitwise.right_shift(x,y,name=None)
with tf.Session() as sess:
print('%d and %d = '%(x,y),sess.run(a))
print('%d or %d = '%(x,y),sess.run(b))
print('%d xor %d = '%(x,y),sess.run(c))
print('%d invert = '%(x),sess.run(d))
print('%d left_shift = '%(x),sess.run(e))
print('%d right_shift = '%(x),sess.run(f))