二进制的变换:
大致就是数字一个数字的二进制的表示,首先进行两两位置的交换。
[1,2,3,4] ==> [2,1,4,3] [1,0,1,0]==> [0,1,0,1]
然后A B C A的最后两位移动到B上,B的最后两位移动到C上,C的最后两位移动到A上,循环移位。
思路不难,按照步骤进行即可。
#输入
1 2
输出:
1073741824 2147483648
from typing import List
# 两两交换数字
def fun2(list2):
res = []
for i in range(0, len(list2)-1, 2):
res.append(list2[i+1])
res.append(list2[i])
return res
# 填充
def fun3(n):
return bin(n)[2:].rjust(32, '0')
list2 = list(map(int, input().split(" ")))
res = []
for i in list2:
res.append("".join(fun2(list(fun3(i)))))
temp = "".join(res)
temp2 = temp[-2:]+temp[:-2]
res2 = []
while len(temp2) > 0:
res2.append(temp2[:32])
temp2 = temp2[32:]
res3 = []
for i in range(len(res2)):
res3.append(int(res2[i], 2))
print(" ".join(map(str, res3)))