Question

Any way to convert Hex to a signed integer - Base converter doesn't support signed values.


Hi Community

 

I have some binary that represents signed 16bit values that I am encoding as hex (with the Binary Encoder) and was hoping to then use the base converter to convert the hex into a signed decimal but it turns out it only supports unsigned conversions :(.

Does anyone have an ideas on how to perform this conversion? I have doen much googling but without any luck.

I would be quite happy to offset all the values by +32767 to get them all into a Unit16 range if there was any way to do that....

 

Cheers!


2 replies

Userlevel 1
Badge +21

You should be able to do this in a python caller

Userlevel 6
Badge +32

This is probably similar to my question earlier. We ended up using a PythonCaller and the struct library.

import fme
import fmeobjects
import struct
 
def processFeature(feature):
    
    binary = feature.getAttribute('measuredValue')
    float = struct.unpack('f', struct.pack('I', int(binary,2)))[0]
    feature.setAttribute("measuredValue",float)

 

Reply