Latest web development tutorials

Python incluye ejercicios 55

Python 100 Li Python 100 Li

Tema: Aprender a usar ~ bit a bit.

Programa de análisis: 0 = 1 ~; ~ 1 = 0;
(1) el derecho de hacer un cuatro.
(2) establecer un bajo 4 son todos 1, el resto son todos los números del cero. ~ Disponible (~ 0 << 4)
(3) tanto de lo anterior será el operador &.

Código fuente:

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

La salida del ejemplo anterior es:

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

Python 100 Li Python 100 Li