# How to represent range of time as bits

I am using bitwise operation to store availability with 1 bit representing one minutes. So one day of availability can be represented by 1 long (8 bytes so 60 bits out of 64 bits) can be used to represent 1 hour so 24 longs will represent availability per day.

Now I have a range of times (ex. 2:00 - 4:00, 15:00 to 17:00) and I need to translate this into bit mask to compare against above longs of availabilities to see if the ranges in the mask is available or unavailable (& with mask) what is the best way to translate this range of times to bits?

-

## 1 Answer

For convenience, use C notation. Let's say a 1 bit in the set means occupied, 0 means free. Then what you want is to get a bit expression that is zero only if all 1 bits in the mask (minutes requested) coincide with 0s in the set, and viceversa; set & mask gives all zeroes if no 1s coinicide, and set | mask asigns the minutes requested.

-