# Decoder issue

**URL:** <https://www.thethingsnetwork.org/forum/t/decoder-issue/66172>\
**Category:** The Things Stack v3\
**Created:** [January 3, 2024, 7:05am UTC](https://www.thethingsnetwork.org/forum/t/decoder-issue/66172 "2024-01-03T07:05:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnet-my](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/a/34f0e0/32.png) [@arnet-my](https://www.thethingsnetwork.org/forum/u/arnet-my)\
**Post date:** [January 3, 2024, 7:05am UTC](https://www.thethingsnetwork.org/forum/t/decoder-issue/66172/1 "2024-01-03T07:05:44Z")

</div>

Hi, I have code that works in any vanilla JS compiler however when I use on TTN v3 the decoder doesn’t work, and I get an error probably due to some JS limitation in TTN?

My code:

```auto
function decodeUplink(input) {

  var data = {};

  // Extracting the last byte as the battery byte
  var batteryHex = input.bytes[input.bytes.length - 1];
  var instantFlow = floatFromHex(input.bytes.slice(6, 14));

  // Battery level calculation
  var battery_level = ((batteryHex - 1) / 253.0) * 100;
  data.battery = battery_level.toFixed();
  data.instantflow = instantFlow;

  return {
    data: data
  };
}

// Helper function to convert bytes to floating-point values with specified endianness

function floatFromHex(hex) {
const hexToUint8 = (str) => Uint8Array.from( str.match( /.{1,2}/g ).map( (comp) => parseInt( comp, 16 ) ));
const [A, B, C, D] = hexToUint8( hex );
const reordered = new Uint8Array( [C, D, A, B] );
const view = new DataView( reordered.buffer ).getFloat32( 0 );

    return view;

}

```

The payload is : 08041831D541E200003FC853D041FB000042A4643B000000DE00007DC02E  
the problem is with instantFlow the result should be 28.274332 I can get that answer in all JS compilers but not in TTN, basically Hex string “31 D5 41 E2” gets byte flipped to “41 E2 31 D5” and as a Float - Mid-Little Endian (CDAB) should be = 1.57 any idea what needs to be changed for it to work correctly in TTN?
