Example #1
0
 def _encode_(self, encodeValue, inProcessPacket):
     """Encodes the provided value into a signed integer fit within the specified number of bytes.
     
     encodeValue -- the signed integer to be encoded.
     """
     twosComplementRepresentation = utilities.signedIntegerToTwosComplement(encodeValue, self.bitSize)  #note that function handles both pos and neg numbers.
     return utilities.unsignedIntegerToBytes(twosComplementRepresentation, self.size) # convert to byte list.
Example #2
0
 def _encode_(self, encodeValue, inProcessPacket):
     """Encodes the provided value into a signed fixed-point decimal."""
     
     bitShiftedValue = encodeValue * 2**self.fractionalBits   #fixed-point encoding is as simple as left-shifting by the fractional bits.
     if self.integerBits > 0:    #signed value
         twosComplementRepresentation = utilities.signedIntegerToTwosComplement(int(bitShiftedValue), self.bitSize) # convert to twos complement
     else:   #no integer bits, unsigned value
         twosComplementRepresentation = bitShiftedValue
     return utilities.unsignedIntegerToBytes(twosComplementRepresentation, self.size)    #convert to byte list