Why is (mmdd >= 0314) different than (mmdd >= 314)

OK, this seems like a simple thing, but I can't explain it. I have a program than is checking for daylight savings time. It determines the month and day, then compares it to the start (and end) of daylight savings time. To boil it down to something simple, if I do:

int mmdd = 306;
Serial.println(mmdd >= 0314);

The result is 1 - which it shouldn't be. 306 is less than 314.

If I do

int mmdd = 306;
Serial.println(mmdd >= 314);

The result is 0 - as expected.

Why is 0314 different than 314? I was originally using 0314 just to kind of document March 14th. I have fixed the code, but want to understand what the compiler is doing. It is a leading zero, not the letter O (which would have generated a compile error anyway).

Thanks.

0314 might be seen as an octal # as it starts with 0.
0314 = decimal 205

0314 is an octal number, because of the leading zero. Its decimal value is 204.

CrossRoads:
0314 = decimal 205

204 !

Never would have guessed that. I would have thought that octal numbers would be entered as something like 0o1234 similar to 0xABCD for hex. But I get it.

I haven't worked with octal numbers in almost 50 years. :confused:

Thanks for the explanation.

I would have thought so too, has bitten me in the past.
Hex = 0x,
Binary = 0b,
yet Octal is just 0.
Likely some history to go with it.

It’s probably (perhaps ironically) a DEC thing! :smiley: