메모장 입니다2
파이썬] ROL, ROR 연산 본문
1. ROL
-Rotate Left
-Shift Left 연산에서, MSB 오버플로우시 LSB로 되돌아온다.
1001 0000 -> 0010 0001
-소스 코드
#RotateLeft Function
def rotateLeft(x, n):
shiftBit = x << n
shiftBit &= 255
carryBit = x >> 8 - n
result= shiftBit | carryBit
return result
#main
ori=0x31
print "ori:{}".format(hex(ori))
print "bin:{}".format(bin(ori))
print "---------------------"
shfData=rotateLeft(ori, 5);
print "shifData:{}".format(hex(shfData))
print "bin:{}".format(bin(shfData))
>결과
2. ROR
def rotateRight(x, n):
shiftBit = x >> n
carryBit = x << (8 - n)
carryBit &= 255
result= shiftBit | carryBit
return result
#main
ori=0x31
print "ori:{}".format(hex(ori))
print "bin:{}".format(bin(ori))
print "---------------------"
shfData=rotateRight(ori, 5);
print "shifData:{}".format(hex(shfData))
print "bin:{}".format(bin(shfData))
'Study > Programming' 카테고리의 다른 글
JAVA] ActionListner 를 이용한 동적 기능 구현 (0) | 2017.08.08 |
---|---|
notepad++ 를 이용하여 컴파일 하기 (0) | 2017.08.08 |
윈도우 역사, 장점 (0) | 2017.08.08 |
임베디드 OS 만들기 -3) 환경 구성(크로스 컴파일, 에뮬레이터) (0) | 2017.08.08 |
임베디드 OS 만들기 - 2) 플랫폼 지정 (0) | 2017.08.08 |