"""
查看所有数据有多少bit
"""
import collections
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
with open("f.txt") as f:
x = f.readlines()
digs = []
for i in x:
if len(i.split(" ")) > 1 :
#print(i.split(" ")[1].split("\n")[0])
d = i.split(" ")[1].split("\n")[0]
if (int(d) > 2**15):
print(d, " more than 15 bits ")
digs.append(len(bin(int(d))) - 2) # '0b' minus
statis = collections.Counter(digs)
print(statis)
# plt.hist(digs) #固定划分10个bins,这里我们要遍历,不知道多少bins,不合适
plt.bar(statis.keys(), statis.values())
plt.show()
print("max ", max(digs))
Counter({12: 221, 13: 215, 11: 195, 14: 174, 10: 152, 9: 148, 8: 103, 15: 93, 7: 69, 6: 50, 5: 33, 1: 29, 4: 25, 3: 16, 2: 13})
max 15
f0
0 0
1 50
2 50
3 101
4 101
5 151
6 151
7 201
8 201
9 251
10 251
11 302
12 302
13 352
14 352
15 402
16 402
17 452
18 452
19 503
20 503
21 553
22 553
23 603
24 603
25 653
26 653
27 704
28 704
29 754
30 754
31 804
32 804
33 855
34 855
35 905
36 905
37 955
38 955
39 1005
40 1005
41 1056
42 1056
43 1106
44 1106
45 1156
46 1156
47 1206
48 1206
49 1257
50 1257
51 1307
52 1307