Latest web development tutorials

Pythonは演習55と、

Pythonの100リー Pythonの100リー

トピック:〜ビット単位を使用することを学んでください。

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

ソースコード:

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

if __name__ == '__main__':
    a = 234
    b = ~a
    print 'The a\'s 1 complement is %d' % b
    a = ~a
    print 'The a\'s 2 complement is %d' % a

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

The a's 1 complement is -235
The a's 2 complement is -235

Pythonの100リー Pythonの100リー