Skip to main content
Question

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

  • May 12, 2021
  • 2 replies
  • 235 views

tim.rastall1
Contributor
Forum|alt.badge.img

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

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • May 12, 2021

You should be able to do this in a python caller


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2938 replies
  • May 12, 2021

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)