I have an object that I am storing bits in.
class Bitset:
def __init__(self, bitstring):
self.bitlist = []
for char in bitstring:
self.bitlist.append(int(char))
def flipBit(self, index):
val = self.bitlist[index]
val = (val + 1) % 2
self.bitlist[index] = val
self.newBitstring()
def bitstring(self):
newString = ''
for val in self.bitlist:
newString = newString + str(val)
return newString
def __len__(self):
return len(self.bitlist)
def __str__(self):
return self.bitstring()
def __repr__(self):
return self.bitstring()
Is there anyway I can convert the bits into a float? Thanks.
float? As a number between 0 and 1? Two's compliment? You need to be more specific?structonly works for floats in IEEE 754 binary format.structto unpack it I am told that the string can only be 4 characters long. Doesn't the standard require 32 bits?