Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bytes_from_file(filename, chunksize=8192):
- with open(filename, "rb") as f:
- while True:
- chunk = f.read(chunksize)
- if chunk:
- for b in chunk:
- yield b
- else:
- break
- FN = 'sample.dat'
- RES = []
- i = 0
- Pon = []
- Poff = []
- res = 0
- # example:
- for by in bytes_from_file(FN):
- if not(i):
- a = int(by)
- A = math.floor(a/2)
- Poff.append(3000*( A & 0b1000000) >> 6)
- Pon.append(3000*(A & 0b0100000) >> 5)
- A = A & 0b0011111
- if not(i%2):
- b = int(by)
- #B = int('{:08b}'.format(b)[::-1], 2)
- B = int(b/2)
- else:
- a = int(by)
- A = math.floor(a/2)
- Poff.append(3000*( A & 0b1000000) >> 6)
- Pon.append(3000*(A & 0b0100000) >> 5)
- A = A & 0b0011111
- #AA = int('{:07b}'.format(A)[::-1], 2)
- #AA = int.from_bytes(A, 'big')
- C = (A << 7) | B
- #CC = (DD << 7) | AA
- #print(i/2,": ",c, a,b,". Corrected ",A,B,". Binary:",bin(A),bin(B),bin(D),bin(C))#bin(a),bin(b))
- #print(int(i/2),hex(b),hex(a),": ","\tBinary\t:",bin(a),bin(A),"\t",bin(b),bin(B),bin(D))#bin(a),bin(b))
- #print(int(i/2),": \t\t\t",bin(A),"\t",bin(B),"\t",bin(C),hex(C),C)
- RES.append(C-2048)
- #print(res)
- res = 0
- i+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement