On Mon, Jul 15, 2002 at 02:25:43PM +0300, Kliment Ognianov wrote:

> Hi all
> Maybe the question is quite stupid but ....... :)
> I've the following problem:
> 
> A counter which counts something .... more exactly it comes as an 
> argument from other script. When it reaches the maximal 32-bit
> integer value I want to reset it automaticaly on 0 and so on again. How 
> can I make it?
> I need only the first 32 bits from this counter, but when it gets over 
> the maximal int val. everything stands 1's ....

Probably the best way is to be explicit.

  if ($val == $COUNTER_LIMIT)
  {
      $val = 0;
  }
  else
  {
      $val++;
  }

You can explicity set $COUNTER_LIMIT to 2**32 - 1 or 2**31 - 1, or
2**31, or whatever it is you actually want and then the chap coming
after you can see what's happening.

If you're concerned about speed, which you may be counting that high, do
the whole thing in C using an unsigned int and let it wrap around
itself.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

  • overflow Kliment Ognianov
    • Paul Johnson

Reply via email to