Integer to bitfield as a list
问题 I've created a method to convert an int to a bitfield (in a list) and it works, but I'm sure there is more elegant solution- I've just been staring at it for to long. I'm curious, how would you convert a int to a bitfield represented in a list ? def get(self): results = [] results.append(1 if (self.bits & 1) else 0) results.append(1 if (self.bits & 2) else 0) results.append(1 if (self.bits & 4) else 0) results.append(1 if (self.bits & 8) else 0) results.append(1 if (self.bits & 16) else 0)