Latest web development tutorials

Python include esercizi 55

Python 100 Li Python 100 Li

Topic: Imparare ad usare bit ~.

Analisi del programma: 0 = 1 ~; ~ 1 = 0;
(1) il diritto di fare un quattro.
(2) ha istituito un basso 4 sono tutti 1, il resto sono tutti a zero numeri. Disponibile ~ (~ 0 << 4)
(3) sia di quanto sopra sarà l'operatore &.

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

L'output sopra esempio è:

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

Python 100 Li Python 100 Li