Skip to content

Instantly share code, notes, and snippets.

View niondir's full-sized avatar

Tobias Kaupat niondir

View GitHub Profile
0xf2980ad42f9295B88f3bD15E1232fA568b4ca840
@niondir
niondir / ttn-float-decoder.js
Last active May 4, 2018 13:32
Float32 and signed int32 decoder for TheThingsNetwork TTN Console
function decodeFloat32(bytes) {
var sign = (bytes & 0x80000000) ? -1 : 1;
var exponent = ((bytes >> 23) & 0xFF) - 127;
var significand = (bytes & ~(-1 << 23));
if (exponent == 128)
return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY);
if (exponent == -127) {
if (significand == 0) return sign * 0.0;
function decodeFloat32(bytes) {
var sign = (bytes & 0x80000000) ? -1 : 1;
var exponent = ((bytes >> 23) & 0xFF) - 127;
var significand = (bytes & ~(-1 << 23));
if (exponent == 128)
return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY);
if (exponent == -127) {
if (significand == 0) return sign * 0.0;