Last active
July 14, 2018 09:04
-
-
Save matiaskorhonen/87ae311ae9347b817596a9e7d080b794 to your computer and use it in GitHub Desktop.
Convert signed hexadecimals from RFLink to floats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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