Example #1
0
def test_int_to_bytes():
    assert _int_to_bytes(512, 2) == b'\x02\x00'
    assert _int_to_bytes(512, 2, endianness='little') == b'\x00\x02'
    assert _int_to_bytes(512, 2, endianness='big') == b'\x02\x00'

    with pytest.raises(TypeError):
        _int_to_bytes('', 2)
Example #2
0
 def _decode(self, value):
     b = _int_to_bytes(value, 9)
     b = list(b)
     b.insert(0, 0)
     b.insert(4, 0)
     b.insert(8, 0)
     b = bytes("".join([chr(x) for x in b]))
     return struct.unpack('<LLL', b)
Example #3
0
 def _decode(self, value):
     b = _int_to_bytes(value, 2)
     return struct.unpack("<h", b)[0]
Example #4
0
 def _decode(self, value):
     b = _int_to_bytes(value, 2)
     r = (b[0] << 4) | (b[1] & 0x0F)
     if r & (1 << 11):
         r = r - 1 << 12
     return r
Example #5
0
 def _decode(self, value):
     return struct.unpack('<H', _int_to_bytes(value, 2))[0]
Example #6
0
 def _decode(self, value):
     b = _int_to_bytes(value, 4)
     return struct.unpack('>f', bytearray(b))[0]
Example #7
0
 def _decode(self, value):
     v = struct.unpack('>h', _int_to_bytes(value, 2))[0]
     return v / 16.0
Example #8
0
 def _decode(self, value):
     integer, fractional = struct.unpack('<bB', _int_to_bytes(value, 2))
     fractional *= 0.0625
     return integer + fractional