How can I convert a string number to a number in Perl?

PHP - How do I convert a 6byte string storing a 48bit floating point to a number in PHP?

  • AMOS supports a 48-bit floating point format consisting of a 40-bit mantissa, 8-bit exponent, and a signbit. Because a normalized mantissa always starts with a binary one in the high-order bit, this bit is not stored in the floating point number but is always assumed to be present. This allows us to represent the 40-bit mantissa in only 39 bits.

  • Answer:

    Try this: $number = unpack('f', $six_byte_string); For more information, see: http://www.php.net/unpack

skett197... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

You probably need to convert it to an IEEE 64-bit floating point (double) by bit-shifting. I don't know how you do this in PHP - if you discover it isn't possible you can write an external program (e.g. in C) to do the conversion for you. Populate a stream with the bits of the 6-byte string, inserting the required bits to pad it to a 64-bit float. Then read in the stream to a double as if you were reading it from a new file.

Marc

sorry

taketwo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.