Instantly share code, notes, and snippets.

# jrg94/LightDistanceCalc.md

Last active December 19, 2016 18:11
Show Gist options
• Save jrg94/820d3f0f482dd19f0170964346381df0 to your computer and use it in GitHub Desktop.
An example of the difference between a 32-bit and 64-bit integer.

# Light Distance Calculation: 32-bit vs. 64-bit

## Some Facts

Maximum Positive Signed 32-bit Integer: `(2^31) - 1 = 2,147,483,647`

Maximum Positive Signed 64-bit Integer: `(2^63) - 1 = 9,223,372,036,854,775,807`

Speed of Light: `299,792,458 m/s`

## If an integer were tracking meters in real time:

### 32-bit Calculation

In seconds: `2,147,483,638 m / 299,792,458 m/s = 7.16323436662 s`

### 64-bit Calculation

In seconds: `9,223,372,036,854,775,807 m / 299,792,458 m/s = 30,765,857,481.5 s`

In minutes: `30,765,857,481.5 s / 60 s/min = 512,764,291.358 mins`

In hours: `512,764,291.358 mins / 60 mins/hour = 8,546,071.52264 hours`

In days: `8,546,071.52264 hours / 24 hours/day = 356,086.313443 days`

In years: `356,086.313443 days / 365.25 days/year = 974.911193547 years`