Ejemplo n.º 1
0
 def test_from_hex(self):
     assert Bits.from_hex(0x0) == Bits([0, 0, 0, 0])
     assert Bits.from_hex(0x0, 1) == Bits([0])
     assert Bits.from_hex(0x0, 2) == Bits([0, 0])
     assert Bits.from_hex(0xa) == Bits([1, 0, 1, 0])
     assert Bits.from_hex(0x48) == Bits([0, 1, 0, 0, 1, 0, 0, 0])
     assert Bits.from_hex(0x100) == Bits(
         [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0])
     assert Bits.from_hex(0xffff) == Bits(
         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
     assert Bits.from_hex(0x0a, 6) == Bits([0, 0, 1, 0, 1, 0])
     assert Bits.from_hex(0xa, 8) == Bits([0, 0, 0, 0, 1, 0, 1, 0])
     assert Bits.from_hex(0x0a, 8) == Bits([0, 0, 0, 0, 1, 0, 1, 0])
Ejemplo n.º 2
0
 def test_from_float(self):
     assert Bits.from_float(1.5) == Bits.from_hex(0x3fc00000, 32)
     assert Bits.from_float(-1.5) == Bits.from_hex(0xbfc00000, 32)
     assert Bits.from_float(0.0) == Bits(size=32)
     assert Bits.from_float(1.2) == Bits.from_hex(0x3f99999a, 32)