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.
Here is a solution that works. as_float32 could be extended to as_float64 by replacing “I” with “L” and “f” with “d”. See the struct documentation for an explanation.