Latest web development tutorials

Python meliputi latihan 55

Python 100 Li Python 100 Li

Topik: Belajar menggunakan bitwise ~.

Analisis Program: 0 = 1 ~; ~ 1 = 0;
(1) hak untuk membuat empat.
(2) mengatur rendah-4 semua 1, sisanya adalah nol angka. Tersedia ~ (~ 0 << 4)
(3) kedua hal di atas akan menjadi & 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

Contoh di atas output:

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

Python 100 Li Python 100 Li