-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbits_eg.py
More file actions
executable file
·70 lines (56 loc) · 2.18 KB
/
bits_eg.py
File metadata and controls
executable file
·70 lines (56 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import glob
import collections
import itertools
import sys
import re
import linecache
def bit_ops(num, bits_to_get_from_lsb):
print('bits_to_get_from_lsb = ' + str(bits_to_get_from_lsb))
local = 0xFF
local = local << bits_to_get_from_lsb
print(hex(local))
bitmask = local & 0xFF
bitmask = bitmask ^ 0xFF
print('bitmask =' + str(hex(bitmask)))
number = num
print('Number is' + str(hex(number)))
print('Passed num is' + str(hex(num)))
var_value = number & bitmask
print('Var value is' + str(hex(var_value)))
print('Number has now become' + str(hex(number)))
number = number >> bits_to_get_from_lsb
print('the input byte is now ' + str(hex(number)))
return (number, var_value)
byte_stream = '10 FC'
byte_string = byte_stream.replace(" ", "")
print('byte_string is ' + byte_string)
bytes = [byte_string[i:i+2] for i in range(0, len(byte_string), 2)]
count = 0
linecount = 0
for i in range(0, len(byte_string)):
one_byte = bytes[i]
print('first byte from left ' + str(one_byte))
one_byte = int(one_byte, 16)
print('first byte from left in hex' + str(hex(one_byte)))
path = 'C:\\Python_programs'
for infile in glob.glob( os.path.join(path, 'sample*') ):
with open(infile) as f:
if linecount != 0:
line = linecache.getline(infile, linecount)
print('Hit the linecount check')
print('The line now points to ' + line)
for line in f:
linecount = linecount + 1
line1 = line.replace(" ", "")
x = re.findall(r':(\w+)', str(line1))
count = count + int(x[0])
print('bits covered so far ' + str(hex(count)))
new_num, var_value = bit_ops(one_byte, int(x[0]))
one_byte = new_num
if count == 8:
print('Exiting Line for loop, 8 bits covered')
print('Lines covered so far ' + str(linecount))
count = 0
break
print(new_num, one_byte, var_value)