Happy Unix Day

In many computer system, time is kept track as number of seconds since midnight on January 1, 1970 (also know as epoch). This time format originated with the Unix system, which is why it’s often referred to as Unix time. At this very instant, the number of seconds since epoch is exactly 1,234,567,890. Happy Unix Day.

I think the next time we’ll probably celebrate is Monday, January 18th, 2038 at 20:14:07 hours. This is when we run into the real millennium bug. Why? Unix time is a 32-bit signed integer (it’s probably a signed integer so that dates before 1 Jan 1970 can be expressed). So, a signed 32-bit number has the range of -231 to +231-1…which is -2,147,483,648 to 2,147,483,647 for everyone who doesn’t want to break out their calculators.

2,147,483,647 turns out to be Monday, January 18th, 2038 at 20:14:07 hours (mountain time). What happens after this? The computer will think it’s Friday, December 13th, 1901 at 12:45:52 hours. Why does it think this? Because computers still count in binary. The important thing to know about a signed binary number is that the sign bit (i.e. how the computer knows if a number is negative or positive, 0 = positive and 1 = negative) is the most significant bit (i.e. the left-most bit). So, if we have a 32-bit signed number, that really means 31-bits worth of numbers, plus a bit for the plus or negative. Thus, the largest positive number we can have is:
0111 1111 1111 1111 1111 1111 1111 1111

…which is 2,147,483,647 in decimal (bonus points if you figure out the hex value of that by converting in your head).

If you add “1” to that binary number, it rolls over to:
1000 0000 0000 0000 0000 0000 0000 0000

…which you might think is negative zero. Of course, you would then ask yourself what’s the difference between negative zero and positive zero. And the answer is: there is none (at least none that most computer programmers care about). So instead of having two versions of zero, some genius decided to have only one version of zero (he kept the positive version), and to make extend the negative range of numbers by one. Thus, two’s compliment was invented and every signed-integer format uses two’s compliment.

To figure out the actual value of a negative number (1000 0000 0000 0000 0000 0000 0000 0000, in our case), you just subtract one and then flip all the bits (all the 1’s become 0’s and all the 0’s become 1’s) and read the resulting value as an unsigned value

So,
Start with: 1000 0000 0000 0000 0000 0000 0000 0000
Subtract 1 to get: 0111 1111 1111 1111 1111 1111 1111 1111
Flip all the bits to get: 1000 0000 0000 0000 0000 0000 0000 0000
Which is: 2,147,483,648 in decimal
But remember we started out with a negative number, so we have to add the negative sign back in to get: -2,147,483,648

And -2,147,483,648 is Friday, December 13th, 1901 at 12:45:52 hours in Unix time.

For what it’s worth, I was really only planning on saying “Happy Unix Day” but I got carried away. Sorry about that.

1FFFFFFFFFFFFFFF

3 Replies to “Happy Unix Day”

  1. Here’s some more interesting time_t values to get unhealthily and geekily overexcited for:
    * At 7:16:58 UTC on October 9th 2010, the Unix time number will reach 9,876,543,210 seconds.

    * At 11:01:20 UTC on July 13, 2012, the Unix time number will reach 0x50000000 (1,342,177,280 seconds), which also happens on a Friday the 13th.

    * At 03:33:20 UTC on May 18, 2033, the second billennium will be celebrated (Unix time number 2,000,000,000).

    By 2038, remember to switch to a 64-bit system. Or swap out your time.h file for one using the (hopefully) upcoming standardized fix.

    But wait! Here are some more dates way into the future to be afraid of:
    * year 292,277,026,596 December 4: 64-bit Unix time overflows.
    * year 170,141,183,460,469,231,731,687,303,715,884,105,727 December 31: 128-bit Unix time overflows.

    We’ll never be safe! 😉

  2. I realize this is an old post however I just wanted to point somethings out… but firstly why I came here.

    I was hoping to find something regarding “Unix Day” being more along the lines of the 20th of November in 2286 for the 10 billion seconds since I missed 1 billion. I was still pleased to read the post since I’ve always liked the idea of keeping track of time with second.

    After reading I thought ‘oh bonus points for me’ after converting 0111 1111 1111 1111 1111 1111 1111 1111 to 7FFFFFFF. Then at the end of your post I saw “1FFFFFFFFFFFFFFF”. I am assuming that was your ‘bonus’ answer… however if so, I think you (at the time) believed 11 was F instead of 1111 as that fits with a 1 followed by 15 F’s.

    Also to anyone reading Jim C’s comment, I stopped at “At 7:16:58 UTC on October 9th 2010, the Unix time number will reach 9,876,543,210 seconds” because that is near 10 billion seconds so I know that was a mistake. After calculation the year 2282… not 2010… … So don’t feel bad you missed it… but don’t expect to live to see it.

    Don’t want to be a downer but things need to be correct. It is Unix time after all… if it were wrong… Y2K would be nothing in comparison to the constant confusion.

    1. I’m going to be honest…I haven’t the slightest clue why I put “1FFFFFFFFFFFFFFF” there. I suspect you may be right though and I goofed with my conversion; that does make the most sense.

Leave a Reply

Your email address will not be published. Required fields are marked *