pythonで2進数に変換

いつも忘れる。たいてい情報処理の試験の前に探してしまう。

>>> print format(128,'b')
10000000
>>> print format(192,'b')
11000000
>>> print format(224,'b')
11100000
>>> print format(240,'b')
11110000
>>> print format(248,'b')
11111000
>>> print format(252,'b')
11111100
>>> print format(254,'b')
11111110
>>> print format(255,'b')
11111111

240がちょうど、11110000 というのを覚えておくと便利なのか。