Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The first thing to say is that you are probably converting to a floating point format, rather than a decimal one. The next thing to notice is that your numbers are 24 bits long, this is not the normal way that modern floating point numbers are encoded they tend to be 32 bit (for example see Wikipedia). From memory I think there was an IBM 24 bit float format from the 1970s.

As you say the bigendian/littleendian split is worth looking at, also sometime these things are written backwards as well (giving 4 combinations of bit order).

The approach I would take is to get as many examples as you can, see if you can encode numbers that are related to each other, for example 1.25, 2.5, 5, 10, 20 and 40. Also select "simple" numbers, like 0.0, 1.0, -1.0 etc and simple relationships, for example compare 0.5, 1.0 and 1.5. Then rewrite every one in binary and see what the patterns are. If you look at the numbers you gave:

0b00111100 10110100 00010101 = 888.997500 0b00000000 01110001 00000010 = 100.000000 0b00000000 00110101 00001100 = 500.000000 0b00000000 01101010 00011000 = 1000.000000 0x00110000 00000101 00010101 = 860.99000 0x10000000 10101001 00000011 = 150.000000 0x11000000 01011110 00000100 = 179.00000

There are obviously too few numbers here to see the pattern but I do notice that 500 and 1000 have an obvious relationship.

Once I understand the conversion I would then use pack (especially with "b") to unpick the parts (for a float that would be the sign, mantissa and exponent and don't forget any implied MSB).

In reply to Re: Convert binary to decimal problem by hawtin
in thread Convert binary to decimal problem by sxmwb

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-09-28 15:28 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (124 votes). Check out past polls.