Skip to content

Instantly share code, notes, and snippets.

View sithwarrior's full-sized avatar

Martin Bech sithwarrior

  • Mobaro A/S
  • Denmark
View GitHub Profile
@mold
mold / get-float-value.js
Created September 12, 2018 12:23
Converting a 4-byte float (IEEE-11073) to a JavaScript number
/**
* Converts a DataView that represents a 4 byte float (IEEE-11073)
* to an actual float. Useful for example when reading temperature
* from a Bluetooth thermometer :)
*
* The DataView buffer should contain at least 4 bytes:
*
* [b0, b1, b2, b3]
* ^ ^ ^ ---------- Exponent
* ------------- Will become the mantissa