-1

If a variable counting hundredth of a second is stored in a signed long 32-bit integer, how many days, to two decimals, will it take until that integer overflows?

1 Answers1

0

Forgoing the nomenclature regarding "long" vs "32-bit integer", assuming you mean a signed 32-bit integer, this is simple to calculate as follows:

  1. Signed 32-bit integer has a maximum value of 2,147,483,647.
  2. When storing 1/100ths of a second, this gives a maximum value of 21,474,836.47 seconds.
  3. There are 86,400 seconds in a day - 60 x 60 x 24 = 86,400.
  4. The value in days is therefore 21,474,836.47 / 86,400 = 248.5513480....
  5. This value to 2dp is 248.55.

Again:

  2147483647    ' Signed 32-bit integer max value
/        100    ' Divide by 100 to get value in seconds
=   21474836.47
/      86400    ' Divide this by seconds in a day
=        248.55 ' Days (rounded to 2dp)

Alternatively you could simply have divided by hundredths of a seconds in a day (8,640,000) to get the same result:

  2147483647    ' Signed 32-bit integer max value
/    8640000    ' Divide by hundredths of a second in a day
=        248.55 ' Days (rounded to 2dp)

Of course, if you actually meant a "long" (a signed 64-bit integer) then the answer becomes the significantly larger 1,067,519,911,673.01days (2dp) which is the equivalent of nearly 3 billion years!

Martin
  • 16,093
  • 1
  • 29
  • 48