pythonExample100/JCP054.py

15 lines
321 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序54】
题目取一个整数a从右端开始的47位。
程序分析:可以这样考虑:
(1)先使a右移4位。
(2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4)
(3)将上面二者进行&运算。
'''
if __name__ == '__main__':
a = int(raw_input('input a number:\n'))
b = a >> 4
c = ~(~0 << 4)
d = b & c
print '%o\t%o' %(a,d)