僕の備忘録(PC、UN*X、ネットワーク関連が中心)なんです。
自分の書いたところは適当(な時とか)に書き換えますので御了承を。
十進表記では わからないのが、ちょっとはわかりやすくなるかも。とPython3.12。
print('\t', end='') for x in [ bin(x)[2:] for x in range(10)]: print(x, end='\t') print('') for x in range(10): print(bin(x)[2:], '\t', end='') for y in range(10): print(bin(x & y)[2:], end='\t') print('')
0 1 10 11 100 101 110 111 1000 1001 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 10 0 0 10 10 0 0 10 10 0 0 11 0 1 10 11 0 1 10 11 0 1 100 0 0 0 0 100 100 100 100 0 0 101 0 1 0 1 100 101 100 101 0 1 110 0 0 10 10 100 100 110 110 0 0 111 0 1 10 11 100 101 110 111 0 1 1000 0 0 0 0 0 0 0 0 1000 1000 1001 0 1 0 1 0 1 0 1 1000 1001
あえて"0b"を落とさないことにする。
import sys x = int(sys.argv[1]) y = int(sys.argv[2]) def amp(x,y): print('{}\tis\t{}'.format(x, bin(x))) print('{}\tis\t{}'.format(y, bin(y))) print('&\tis\t',bin(x & y), sep='') amp(x,y)
$ python3 defamp3.py 5 9 5 is 0b101 9 is 0b1001 & is 0b1
"""を使って、printを一つで済ませることも試したが、綺麗に見えないのでやめる。
桁数が合ってないので、ちょっと見づらいけど、それはまた次回にしよう。
24+42とか、17+71などは、すべて11の倍数になるという。
def change(x): return int(x / 10) + x % 10 * 10 for x in range(10,100): y = change(x) z = x + y print("{} and {} is {}, {} % 11 is {}" .format(x, y, z, z, z % 11))
$ python3 change2.py 10 and 1 is 11, 11 % 11 is 0 11 and 11 is 22, 22 % 11 is 0 12 and 21 is 33, 33 % 11 is 0 13 and 31 is 44, 44 % 11 is 0 14 and 41 is 55, 55 % 11 is 0 (ry 95 and 59 is 154, 154 % 11 is 0 96 and 69 is 165, 165 % 11 is 0 97 and 79 is 176, 176 % 11 is 0 98 and 89 is 187, 187 % 11 is 0 99 and 99 is 198, 198 % 11 is 0
前にもうちょっとましなのを書いた気がするが、よく思い出せない。
リンクはご自由にどうぞ。でもURLや内容が変った場合はあしからず。