# Another Payload Decoder Question (issues converting bytes to float)

**URL:** <https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879>\
**Category:** Application Development\
**Created:** [February 7, 2021, 1:51am UTC](https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879 "2021-02-07T01:51:18Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![shed](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/shed/32/36037_2.png) [@shed](https://www.thethingsnetwork.org/forum/u/shed)\
**Post date:** [February 8, 2021, 8:36am UTC](https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879/4 "2021-02-08T08:36:50Z")

</div>

The solution, as per here:

> [@Dragino LGT-92 - LoRaWAN GPS Tracker](https://www.thethingsnetwork.org/forum/t/dragino-lgt-92-lorawan-gps-tracker/21817/62):
>
> Like I explained it indeed looks like that, but (luckily!) it doesn’t do anything. As you quoted from my explanation: JavaScript works with 32 bits for bitwise operators, so it will handle 0xFFFFFFFF00000000 as if it were 0x00000000 here. Just try 0xFFFFFFFF00000000 | 0xFFFFFFFF00000000 to see that evaluates to zero. Even more, if it would have an effect, then it would erroneously set bits that did not need to be set, as the value was already 32 bits, so would already be negative if applicabl…

Was to multiply by 1000000, like so:

```
cpu_temp_pack = struct.pack('h', int(cpu_temp))
bat_pack = struct.pack('h', int(bat))
lat_pack = struct.pack('i', int(lat * 1000000))
lon_pack = struct.pack('i', int(lon * 1000000))

```

Then decode like so:

```
payload = (bat_pack + cpu_temp_pack + lat_pack + lon_pack)

function Decoder(bytes, port) {
  var decoded = {};

  if (port === 1) 
  { 
    decoded.bat = (bytes[1] << 8) | bytes[0];
    decoded.cpu_temp = (bytes[3] << 8) | bytes[2];
    decoded.lat = (bytes[7]<<24 | bytes[6]<<16 | bytes[5]<<8 | bytes[4]) / 1000000;
    decoded.lon = (bytes[11]<<24 | bytes[10]<<16 | bytes[9]<<8 | bytes[8]) / 1000000
  }

  return decoded;
}

```

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879)._
