Advertisement
Andruwkoo

Untitled

Jan 17th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. def bytes_from_file(filename, chunksize=8192):
  2.     with open(filename, "rb") as f:
  3.         while True:
  4.             chunk = f.read(chunksize)
  5.             if chunk:
  6.                 for b in chunk:
  7.                     yield b
  8.             else:
  9.                 break
  10.                
  11. FN = 'sample.dat'
  12.  
  13. RES = []
  14. i = 0
  15.  
  16. Pon = []
  17. Poff = []
  18. res = 0
  19. # example:
  20. for by in bytes_from_file(FN):
  21.     if not(i):
  22.         a = int(by)
  23.         A = math.floor(a/2)
  24.         Poff.append(3000*( A & 0b1000000) >> 6)
  25.         Pon.append(3000*(A & 0b0100000) >> 5)
  26.         A = A & 0b0011111
  27.  
  28.     if not(i%2):
  29.         b = int(by)
  30.         #B = int('{:08b}'.format(b)[::-1], 2)
  31.         B = int(b/2)
  32.     else:
  33.         a = int(by)
  34.         A = math.floor(a/2)
  35.         Poff.append(3000*( A & 0b1000000) >> 6)
  36.         Pon.append(3000*(A & 0b0100000) >> 5)
  37.         A = A & 0b0011111
  38.         #AA = int('{:07b}'.format(A)[::-1], 2)
  39.         #AA = int.from_bytes(A, 'big')
  40.        
  41.         C = (A << 7) | B
  42.         #CC = (DD << 7) | AA
  43.         #print(i/2,": ",c, a,b,". Corrected ",A,B,". Binary:",bin(A),bin(B),bin(D),bin(C))#bin(a),bin(b))
  44.         #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))
  45.         #print(int(i/2),": \t\t\t",bin(A),"\t",bin(B),"\t",bin(C),hex(C),C)
  46.         RES.append(C-2048)
  47.         #print(res)
  48.         res = 0
  49.     i+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement