given following scale:
mon = 64, tue = 32, wed = 16, thu = 8, fri = 4, sat = 2, sun = 1
how create function passed integer decode corresponding days of week?
for example, value 127 passed, how can determine days included in value?
sounds bitmask. can read bitmasks here; http://en.wikipedia.org/wiki/mask_%28computing%29
sunday 1st bit, sat 2nd, etc, mon 7th. see if day included, use binary and.
var listofdays = 127; var hassun = listofdays & 1; var hassat = listofdays & 2; var hasfri = listofdays & 4; // etc
Comments
Post a Comment