Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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|improve this question
add comment

1 Answer 1

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|improve this answer
add comment

Your Answer

 
discard

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.