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);

...

  }
4
  • 1
    readFloatBE() expects 32 bits input, but your sliced buffer is 64 bits. Shouldn't you be using readDoubleBE() which expects 64 bits. Commented Jan 1, 2021 at 2:15
  • Brilliant! I was just being braindead and taking the notes at face value 😅 Commented Jan 1, 2021 at 2:25
  • 1
    Happy new year 😅 Commented Jan 1, 2021 at 2:27
  • Happy New Year Bro 🎊😊🍾 Commented Jan 1, 2021 at 2:53

1 Answer 1

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

console.log( buf.readDoubleBE(0) );
// Prints: 604.274335557087
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.