Today’s Date is Binary!

You know you’re a nerd when you look at today’s date, November 1st, as 11-01 and then you think, “That’s a binary number!” Yeah, nerd.

When thinking of a topic for today’s Lesson, I kept fixating on the date. It got me thinking about how many other dates through the year — month/date combinations — are binary in nature, using only the digits one and zero?

If this were a trivia question during a pub quiz, I’d riffle though my brain to come up with a quick answer. (And if you’re a nerd, you’ve probably already done so.) But instead, and seeing how this post is supposed to be about C programming, I thought I’d write code that would find all the annual binary dates and output the entire list.

This first part of this code is presented below. It’s a program that churns through the months and days of the year, outputting each as a two-digit value. After all, if you’re going to hunt for those binary dates, you must generate the full field in which to search. Consider this code an initial step.

2025_11_01-Lesson.c

#include <stdio.h>

int main()
{
    int month,d;
    int days[12] = {
        31, 28, 31, 30, 31, 30,
        31, 31, 30, 31, 30, 31
    };

    for( month=0; month<12; month++ )
    {
        for( d=0; d<days[month]; d++ )
            printf("%02d%02d\n",
                    month+1,
                    d+1
                  );
    }

    return 0;
}

Integer variable month tracks months of the year; int variable d tracks the days of a month.

Array days[] holds the number of days in each month. Because February 29th isn’t a binary value, I just omitted it as well as any silly leap year calculations.

Nested for loops work through the month and day values. The printf() statement outputs the month/day date as four-digit value. The %02d placeholder ensures that output is in the format of a decimal integer, two-digits wide, with a leading zero for single-digit values. The value 1 is added to variables month and d in the printf() statement to make the output human-readable.

Here’s the output:

0101
0102
0103
0104
0105
0106
.
.
.
1227
1228
1229
1230
1231

That’s 365 lines of output, each expressing a day of the years as a date two digits wide.

The next phase of the project is to set this output into a form that can be tested for binary values. I continue this task in next week’s Lesson.

Leave a Reply