Latest web development tutorials

Python beinhaltet 55 Übungen

Python 100 Li Python 100 Li

Thema: Lernen bitweise zu verwenden ~.

Programmanalyse: 0 = 1 ~; ~ 1 = 0;
(1) das Recht, eine vier zu machen.
(2) die Einrichtung eines Low-4 sind alle 1, der Rest sind alle Null-Nummern. Verfügbar ~ (~ 0 << 4)
(3) beide der oben genannten wird der & Operator.

Source Code:

#!/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

Das obige Beispiel Ausgabe lautet:

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

Python 100 Li Python 100 Li