Skip to content

Instantly share code, notes, and snippets.

@asi-msk
Created August 11, 2022 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asi-msk/ed4ecef8434b2b6e03bf27cf92ca2bae to your computer and use it in GitHub Desktop.
Save asi-msk/ed4ecef8434b2b6e03bf27cf92ca2bae to your computer and use it in GitHub Desktop.
8bitマイコンで比較的楽に曜日を何とかする方法(2000-2099のみの対応)
#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