1 # 位运算符 2 number = 32 3 number2 = -32 4 print(number, "左移一位:", number << 1) 5 print(number, "右移一位:", number >> 1) 6 print(number2, "左移一位:", number2 << 1) 7 print(number2, "右移一位:", number2 >> 1)
运行结果
1 # 位运算符 2 number = 31 3 number2 = -31 4 print(number, "左移一位:", number << 1) 5 print(number, "右移一位:", number >> 1) 6 print(number2, "左移一位:", number2 << 1) 7 print(number2, "右移一位:", number2 >> 1)
运行结果
1 # 位运算符 2 number = 0 3 print(number, "左移一位:", number << 1) 4 print(number, "右移一位:", number >> 1)
运行结果