Lets see, The hours array looks like taken/free hours in a day (length of 7)
How do you know if the hour at day x is taken?
Check the bit values in hours[x] If the 3rd bit is on - the 3rd hour is taken
Lets take for example the following array [9,0,0,2,0,0,0] Sundays value is 9 which means it's bits look like 1001 => the 1st hour is taken and the 4th. Wednesdays value is 2 which means its 2nd hour is taken. All other days are free
Now lets take a look at the code
AddNewShift: It "activates" all the hours from startTime => endTime in the given days array. How? |= Lets look at an example X |= 1 means that what ever x contains i want that the first bit will be activated Its like X = X | 1 | means the OR bitwise operation
So in our code hours[d] |= some int Means to activate 'some int' hours in 'd' day
For example If our hours array will be [0,0,0,0,0,0,0] And the day array will be [0,1] For hours[d] |= 3 Will get [3,3,0,0,0,0,0] We activated hours 1,2 in the 1st,2nd days
1 << i If im not mistaken means to shift left 1 i times So 1 << 3 will be the number 8 We moved it 3 bits left In the function we do that for each hour from startTime until endTime, why? We want to "activate" that hour in all the given days
Unfortunately i ran out of time to explain the second function..