我有转码输入十六进制数字的功能。例如,我有这样的数字初始格式
并且函数将其转码为这种格式:
我将使用十六进制内置函数将函数的结果作为字符串返回。我尝试过这样的事情,但没有奏效:
def task22(number) -> str:
"""
Returns transcoded hexadecimal string, this function uses bitwise operators to transcode given value
:param number: hexadecimal number to transcode
:return: Transcoded hexadecimal string
"""
a = number & 0b111111111111111
b = number & 0b111111111111111
c = number & 0b11
a = a << 17
b = b >> 13
c = c >> 30
return hex(a | b | c)
如何使用按位运算符对数字进行转码?我需要向左和向右使用按位移位,但我不知道如何为上述格式执行此操作。