<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pulkit (Ryo)</title>
    <description>The latest articles on DEV Community by Pulkit (Ryo) (@ryo112358).</description>
    <link>https://dev.to/ryo112358</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F363975%2Fc368499e-8900-4230-b8b2-2c1eb6107e2f.png</url>
      <title>DEV Community: Pulkit (Ryo)</title>
      <link>https://dev.to/ryo112358</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ryo112358"/>
    <language>en</language>
    <item>
      <title>The Restart of Time</title>
      <dc:creator>Pulkit (Ryo)</dc:creator>
      <pubDate>Thu, 10 Jun 2021 22:38:43 +0000</pubDate>
      <link>https://dev.to/ryo112358/the-restart-of-time-7b3</link>
      <guid>https://dev.to/ryo112358/the-restart-of-time-7b3</guid>
      <description>&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A basic knowledge of bits, bytes, and words&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Refresher:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://csanim.com/tutorials/intro-binary-numbers-bitwise-operations-ultimate-visual-guide"&gt;Intro to Binary Numbers | CSAnim&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/aidiri/intro-to-x-bit-and-binary-integers-39lj"&gt;Intro to Binary Integers | Aidi Rivera&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Have you ever asked yourself how time is represented in a computer? How about whether we're on the verge of running out of bits to store said time?&lt;/p&gt;

&lt;p&gt;If yes, fantastic. Let's get to the bottom of it. If not, I hope your interest is piqued. Keep reading and we can learn something together!&lt;/p&gt;




&lt;h2&gt;
  
  
  The Representation of Time
&lt;/h2&gt;

&lt;p&gt;We'll start with the simpler question, the representation of time in bits.&lt;/p&gt;

&lt;p&gt;In computer science, &lt;span title="Reading on Unix epoch below in 'References'"&gt;we generally record &amp;amp; store time in milliseconds relative to January 1st, 1970&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;Knowing this, you may find yourself wondering:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Well there are 1000 ms in EVERY second and that has to add up fast. We're already 50 years past the epoch and that's a lot of milliseconds! Won't we run out of bits soon, say in a few decades?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Good news is that we've little to worry about and even better, I'll show you why.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Magnitude of Time in Millis
&lt;/h2&gt;

&lt;p&gt;Let's get a feel for the scale of milliseconds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span title="(Cool, looks manageable)"&gt;1 sec = 1,000 ms&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span title="(Well that was a big jump ^_^')"&gt;1 min = 60 sec = 60,000 ms&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;
&lt;span title="(Spongebob, you're spending all me bits!)"&gt;&lt;strong&gt;1 day&lt;/strong&gt; = 1,440 min = &lt;strong&gt;86,400,000 ms&lt;/strong&gt; &lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span title="(...!!!) ヽ(ಠ_ಠ)ノ"&gt;1 year = 365 days = 31,536,000,000 ms&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hmmmmm... so &lt;strong&gt;~32 billion milliseconds go by each year.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Seems like a rather large value for a &lt;em&gt;single&lt;/em&gt; year, doesn't it?&lt;/p&gt;




&lt;h2&gt;
  
  
  The Magnitude of the Container
&lt;/h2&gt;

&lt;p&gt;Now we'll get a feel for the scale of our data types which will hold the milliseconds elapsed since a given date.&lt;/p&gt;

&lt;p&gt;While word sizes can be 32 or 64 bits, we forgo one bit in order &lt;span title="meaning time in the past, before 1970"&gt;to represent negative values, i.e. time before the Unix epoch.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signed Max Values&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;32-bit word: 2^31 = 2,147,483,648 ≈ 2.15E9&lt;/li&gt;
&lt;li&gt;64-bit word: 2^63 = 9,223,372,036,854,775,808 ≈ 9.2E18&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the number of milliseconds in a year is 3.15E10, we've already surpassed the size of a 32-bit word. But there's still hope!&lt;/p&gt;




&lt;p&gt;A 64-bit word can represent a value several magnitudes higher than a year of milliseconds, i.e. &lt;span title="Signed 64-bit Max Value: 9.2E18"&gt;10&lt;sup&gt;18&lt;/sup&gt;&lt;/span&gt; vs &lt;span title="Milliseconds in a year: 3.15E10"&gt;10&lt;sup&gt;10&lt;/sup&gt;&lt;/span&gt;, but just how many years?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;9,223,372,036,854,775,808 ms ÷ 31,536,000,000 ms/yr  = 292,471,208.68 years&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A 64-bit word can represent time a colossal 2.9E8 years to either end of a given date, i.e. &lt;strong&gt;~290 million years in the past or future&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So maybe if humans are still around by &lt;code&gt;268,435,456 AD (2^28)&lt;/code&gt;, we'll need a v2 of the Unix epoch, the restart of time.&lt;/p&gt;

&lt;p&gt;Perhaps we'll decide to reset at a happier number, e.g. 250,000,000 AD.&lt;/p&gt;

&lt;p&gt;I imagine by then our processors will support much higher word sizes, e.g. x256, x2048, and beyond. I personally can't fathom practical uses of word sizes over 128-bits aside from cryptography. However, intergalactic conquest &amp;amp; expansion may prove this point moot.&lt;/p&gt;

&lt;p&gt;In any case, we can put our minds at ease. The restart of time of time won't happen on our watch. 🥁&lt;/p&gt;

&lt;p&gt;Until Next Time,&lt;br&gt;
Pulkit&lt;/p&gt;




&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/System.html#currentTimeMillis()"&gt;System API | JDK 16 Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kb.narrative.io/what-is-unix-time"&gt;Unix Time | Narrative.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/1090869/why-is-1-1-1970-the-epoch-time"&gt;Why is 1/1/1970 the “epoch time”? | StackOverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/2533563/why-are-dates-calculated-from-january-1st-1970"&gt;Why are dates calculated from January 1st, 1970? | StackOverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Further Reading:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.hackerearth.com/practice/basic-programming/bit-manipulation/basics-of-bit-manipulation/tutorial/"&gt;Basics of Bit Manipulation | HackerEarth&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Published on Medium
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://coffeelessprogrammer.medium.com/the-restart-of-time-2aab3f19bde0?source=friends_link&amp;amp;sk=1a1cac750a6aa8f1ed9ee3bbb10499eb"&gt;The Restart of Time | CoffeelessProgrammer | Medium&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>coffeelessthoughts</category>
      <category>todayilearned</category>
      <category>devjournal</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
