Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.