ROL(Rotate Left)
왼쪽으로 단순 shift 연산 하는 것이 아닌 회전하는 방식으로 연산함
연산자 | 연산 |
---|---|
SHL | 10000000 -> 00000000 |
ROL | 10000000 -> 00000001 |
def rol(x, n):
shiftBit = x >> n
carryBit = x << (8 - n)
carryBit &= 255
return shfitBit | carryBit
ROR(Rotate Right)
오른쪽으로 단순 shift 연산 하는 것이 아닌 회전하는 방식으로 연산함
연산자 | 연산 |
---|---|
SHR | 00000001 -> 00000000 |
ROR | 00000001 -> 10000000 |
def ror(x, n):
shiftBit = x << n
shiftBit &= 255
carryBit = x >> (8 - n)
return shfitBit | carryBit
'언어 > Python' 카테고리의 다른 글
little endian hex to int (0) | 2024.08.01 |
---|---|
int to byte 변환 (0) | 2024.08.01 |