Toán tử dịch chuyển bên trái Bitwise Các nhà khai thác bitwisex other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
1
class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
2class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
3class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
4class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
5class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
6class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
7class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
8class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
9class Data:
def __init__[self, data]:
self.data = data
def __and__[self, other]:
return Data[self.data & other.data]
def __or__[self, other]:
return Data[self.data | other.data]
def __xor__[self, other]:
return Data[self.data ^ other.data]
def __invert__[self]:
return Data[~self.data]
def __lshift__[self, other]:
return Data[self.data > other.data]
x = 2
y = 3
print['Operands: \n', 'x =', x, '\n', 'y =', y]
print[]
print['Bitwise AND: ', x & y]
print['Bitwise OR: ', x | y]
print['Bitwise XOR: ', x ^ y]
print['Bitwise NOT: ', ~x]
print['Bitwise LEFT-SHIFT: ', x > y]
0Operands:
x = 2
y = 3
Bitwise AND: 2
Bitwise OR: 3
Bitwise XOR: 1
Bitwise NOT: -3
Bitwise LEFT-SHIFT: 16
Bitwise RIGHT-SHIFT: 0
1Operands:
x = 2
y = 3
Bitwise AND: 2
Bitwise OR: 3
Bitwise XOR: 1
Bitwise NOT: -3
Bitwise LEFT-SHIFT: 16
Bitwise RIGHT-SHIFT: 0
2Ở đây, một ví dụ về cách thực hiện các toán tử bitwise này trên lớp tùy chỉnh Operands:
x = 2
y = 3
Bitwise AND: 2
Bitwise OR: 3
Bitwise XOR: 1
Bitwise NOT: -3
Bitwise LEFT-SHIFT: 16
Bitwise RIGHT-SHIFT: 0
3. Chúng tôi đã đánh dấu toán tử tương ứng này trong mã:Đầu ra là:
Các toán tử bitwise thực hiện các hoạt động trên biểu diễn nhị phân [bit] của các số nguyên. Bảng sau đây đưa ra một cái nhìn tổng quan ngắn về tất cả các toán tử bitwise hiện có. Lưu ý rằng chúng tôi cũng cung cấp biểu diễn nhị phân
Operands: x = 2 y = 3 Bitwise AND: 2 Bitwise OR: 3 Bitwise XOR: 1 Bitwise NOT: -3 Bitwise LEFT-SHIFT: 16 Bitwise RIGHT-SHIFT: 04 cho số nguyên thập phân
Operands: x = 2 y = 3 Bitwise AND: 2 Bitwise OR: 3 Bitwise XOR: 1 Bitwise NOT: -3 Bitwise LEFT-SHIFT: 16 Bitwise RIGHT-SHIFT: 05 và
Operands: x = 2 y = 3 Bitwise AND: 2 Bitwise OR: 3 Bitwise XOR: 1 Bitwise NOT: -3 Bitwise LEFT-SHIFT: 16 Bitwise RIGHT-SHIFT: 06 cho số nguyên thập phân
Operands: x = 2 y = 3 Bitwise AND: 2 Bitwise OR: 3 Bitwise XOR: 1 Bitwise NOT: -3 Bitwise LEFT-SHIFT: 16 Bitwise RIGHT-SHIFT: 07 như một nhận xét trong cột bên phải.
Nhà điều hành