Hi, Sorry if this is already asked, but I couldn't find it.

I got a text file with 100010101001000010000011111001010 and it is 8bit, now I would like it to decimal.

With the int(file,2) function it does not work. I get a very large number. Is there an extra command I can add to the int() function or how do I fix this?

Thanks

It doesn't look like 8 bit. It looks more like 33 bit.

>>> int("100010101001000010000011111001010", 2)
4649453514

What result do you want?

Maybe it's four 8-bit numbers together?

>>> i = '100010101001000010000011111001010'
>>> first_num = int(i[:8],2)
>>> secnd_num = int(i[8:16],2)
>>> third_num = int(i[16:24],2)
>>> fourt_num = int(i[24:32],2)
>>> first_num
138
>>> secnd_num
144
>>> third_num
131
>>> fourt_num
229
>>>

Sorry, for not enough info. It are indeed multiple 8bit numbers.
It is part of hacking an usb mouse, if you want more info I can give it.

I updated your script jlm699, thanks for the info.

filename = "test.dat"
FILE = open(filename,"r")
text = FILE.read()
bitamount = len(text) / 8

start = 0
end = 8
i = 0

print "Total amount of decimal numbers is %s" % (bitamount)
while i < bitamount:
    
    print int(text[start:end],2)
    start = start +8
    end = end + 8
    i = i +1    

FILE.close()
print "done"
This question has already been answered. Start a new discussion instead.