I have a very long string of bits (500 bits of 0s and 1s only). How do I convert this to decimal in sets of 4 (i.e a nibble of 4 bits)?
I tried the following approach, but it doesn't work (followed from here)
with open("atb.bat","rb") as file: # atb.bat is the file which contains the string
data=file.read(4)
with open("out.txt","w") as f:
f.write(" ".join(map(str,data)))
f.write("\n")
I expect the output to be 125 integers but end up with only 4 decimal values!
I also tried something like this
p1 = 100000001111100101110011001101100110010 # (for example)
p22 =np.packbits(p1,axis=0)
but doesn't work!
Any ideas? Thanks