Latest web development tutorials

Pythonは演習54と、

Pythonの100リー Pythonの100リー

タイトル:4〜7ビットの右端から整数を取ります。

プログラム解析:この点を考慮してください。
(1)は、4つを行う権利を。
(2)低4を設定し、すべての1であり、残りはすべてゼロの数字です。 利用可能な〜(〜0 << 4)
(3)上記の両方は、&演算子となります。

ソースコード:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

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)

上の例の出力は、次のとおりです。

input a number:
9
11	0

Pythonの100リー Pythonの100リー