Created
August 11, 2022 10:50
-
-
Save asi-msk/ed4ecef8434b2b6e03bf27cf92ca2bae to your computer and use it in GitHub Desktop.
8bitマイコンで比較的楽に曜日を何とかする方法(2000-2099のみの対応)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
uint8_t calc_day_of_week(uint8_t year, uint8_t month, uint8_t day) { | |
const uint8_t non_leap[] = {6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; | |
const uint8_t leap[] = {5, 1, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4, 0}; | |
if (year & 0b11) { | |
return (year + year / 4 + non_leap[month - 1] + day) % 7; | |
} else { | |
return (year + year / 4 + leap[month - 1] + day) % 7; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment