Skip to content

Instantly share code, notes, and snippets.

@matiaskorhonen
Last active July 14, 2018 09:04
Show Gist options
  • Save matiaskorhonen/87ae311ae9347b817596a9e7d080b794 to your computer and use it in GitHub Desktop.
Save matiaskorhonen/87ae311ae9347b817596a9e7d080b794 to your computer and use it in GitHub Desktop.
Convert signed hexadecimals from RFLink to floats
# Convert signed hexadecimals from RFLink to floats
def signed_to_float(hex)
int = hex.to_i(16)
if int & 0x8000 > 0
-(int & 0x7FFF).to_f / 10
else
int.to_f / 10
end
end
signed_to_float("80DC")
# => -22.0
signed_to_float("00C0")
# => 19.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment