1

I have a byte array: [93, 156, 244, 63]

I want to convert it to a floating point number, it should be ~9.8.
How exactly would I go about doing this in JS? I am rusty when it comes to bitwise operations.

Thanks in advance.

edit: The array should be [92,209,28,65]

4
  • 1
    Can you elaborate more on the process and show your own attempts ata solution? Commented May 19, 2017 at 0:39
  • 1
    Chris, listen to Chris's comment :) - I assume you want to know how to interpret an array of four bytes (little-endian) as a single 32-bit IEEE float? Commented May 19, 2017 at 0:43
  • 1
    In what encoding [93, 156, 244, 63] is 9.8? Commented May 19, 2017 at 0:44
  • 3
    9.8 would correspond to [ 205, 204, 28, 65 ] (bytes of a 32-bit float) Commented May 19, 2017 at 0:49

1 Answer 1

7

If it is a IEEE754 single precision floating number you might do:

new Float32Array(new Uint8Array([93, 156, 244, 63]).buffer)[0]

But it returns 1.9110218286514282 for the bytes you provided.

And you may see that 1.911... matches those bytes: http://www.binaryconvert.com/result_float.html?decimal=049046057049049048050049056050056054053049052050056050

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.