0

I have a large DAT file that holds custom byte information,
And I've been tasked with converting the solution to JavaScript.
It's to make the solution be more single-language and convert to serverless cloud computing.

But, I've run into an issue with converting this test data.
The values supposed to return a float,
But I can't seem to get the number converted correctly.

The sliced buffer output is <Buffer 40 82 e2 31 d6 d7 2e 8d>,
Which is supposed to return 604.274335557087
But actually returns 4.090111255645752.

And I'm at my wits end right now.
Any thoughts?


  fs.readFile(file, (err, data) => {

...
      // Read other buffer slice() values fine until this step. 
      // Like: readInt8(), readIntBE(0, 4), readBigUInt64BE(0, 8) 
...

      let FloatNumber = data.slice(start, end).readFloatBE();
      console.log('FloatNumber', FloatNumber);

...

  }
Zach
  • 539
  • 1
  • 4
  • 22

1 Answers1

1
const buf = Buffer.from([0x40, 0x82, 0xe2, 0x31, 0xd6, 0xd7, 0x2e, 0x8d]);

console.log( buf.readDoubleBE(0) );
// Prints: 604.274335557087
JohnRC
  • 1,251
  • 1
  • 11
  • 12