Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Finding the pattern in a set of values

  1. Jun 30, 2011 #1
    I have this set of binary values, but the way to arrive at them remains a mystery. I would appreciate some help on that issue.
    Code (Text):
    Value(LEndian)  Start Diff  Prev Diff   Resulting Multiplier
    16256       +0      +0      1
    16272       +16     +16     1.125
    16288       +32     +16     1.25
    16320       +64     +32     1.5
    16384       +128        +64     2
    16512       +256        +128        4
    16640       +384        +128        8
    16768       +512        +128        16
    16896       +640        +128        32
     
    The question being how do you arrive at the corresponding multiplier from the given value.
     
  2. jcsd
  3. Jun 30, 2011 #2

    I like Serena

    User Avatar
    Homework Helper

    Hi martix! :smile:

    Your Value is the 'single precision' float representation of your Resulting Multiplier.
    Or to be more precise, only the top two bytes that should be in there.
    See this wiki page for details: http://en.wikipedia.org/wiki/Single_precision

    If you want a formula, it's:
    [tex]Multiplier = (1 + \frac {Value \textrm{ MOD } 128} {128}) \cdot 2^{Value \textrm{ DIV } 128 - 127}[/tex]
    In this formula MOD means to take the remainder after division.
    And DIV means to take the integer part after division.

    Btw, you missed 2 bytes in your Value. It's supposed to be a 4 byte value.
    Those 2 bytes would have been zero for the numbers you've put into your table.
    But the consequence would be that the numbers in your Value column should actually be 65536 times as large.
     
    Last edited: Jun 30, 2011
  4. Jun 30, 2011 #3

    rcgldr

    User Avatar
    Homework Helper

    Those values are the 16 most significant bits of single precision (32 bit floating point) numbers:

    Code (Text):

    multiplier      hex      decimal   hex   value
     1.0000 => 3f800000 = 1065353216  3f80 = 16256
     1.1250 => 3f900000 = 1066401792  3f90 = 16272
     1.2500 => 3fa00000 = 1067450368  3fa0 = 16288
     1.5000 => 3fc00000 = 1069547520  3fc0 = 16320
     2.0000 => 40000000 = 1073741824  4000 = 16384
     4.0000 => 40800000 = 1082130432  4080 = 16512
     8.0000 => 41000000 = 1090519040  4100 = 16640
    16.0000 => 41800000 = 1098907648  4180 = 16768
    32.0000 => 42000000 = 1107296256  4200 = 16896
     
     
    Last edited: Jun 30, 2011
  5. Jun 30, 2011 #4

    I like Serena

    User Avatar
    Homework Helper

    Divide your numbers by 65536 and you'll find a match.

    Actually, I had just edited my previous post to explain that. ;)
     
  6. Jun 30, 2011 #5

    rcgldr

    User Avatar
    Homework Helper

    Was in the process of updating my post, it's fixed now.
     
  7. Jun 30, 2011 #6

    I like Serena

    User Avatar
    Homework Helper

    Nice table! It clarifies quite neatly what is going on. :smile:
     
  8. Jun 30, 2011 #7
    I just had a massive FACEPALM. How I didn't see that I have no idea.
    The data was in little endian and there were a lot of zeros before those values in every structure they were present so that might have been it.

    Anyway, thank you very much!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Finding the pattern in a set of values
  1. Design Patterns (Replies: 2)

  2. Pattern Recognition (Replies: 1)

Loading...