Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a packetized binary data file that can be referenced in one of two ways:

  1. By an arbitrary time tick counter, and
  2. By a file offset in bytes.

In my example file, I have the following packet locations:

ticks           file offset
729047097              3214   <-- Location of first packet
739047132          37492760   <-- Location of last packet
---------          --------
 10000035          37494046   <-- Differences

I need a function that I can present start and end ticks, start and end offsets, and a candidate number of ticks between the start and end ticks, and have it return the corresponding file offset.

I already know that I can compute a Bytes per Tick value, and then multiply that by (candidate ticks minus start ticks), but what I would like to know is:

  1. What is the general form of this function, and
  2. Is there a name for this general form?
share|improve this question

1 Answer 1

up vote 4 down vote accepted

If I understand correctly what you're trying to do, it's called linear interpolation, and the formula for it is

$$o(t)=o_0+(t-t_0)\frac{o_1-o_0}{t_1-t_0}\;,$$

where $o_0$, $o_1$ and $t_0$, $t_1$ are the file offsets and ticks at start and end, respectively, and $o(t)$ is the file offset corresponding to tick $t$. The "bytes per tick" value is the fraction on the right. How to arrive at this is explained in the Wikipedia article.

share|improve this answer
    
Yes! I knew there was a name for it, I just couldn't remember. –  Robert Harvey Aug 9 '11 at 23:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.