yes. the maximum number of bits you can set by inverting bits is the number you set. if you are setting 5 bits, the max is 5. (bad question?)
now say you have some simple example..
000111 .. there are a few answers for flipping 5 here.
111001 .. you can say you set 1 bit by flipping 5, or you can say you set 3 and lost 2. Its all in whether you look at it technically or holistically. Technically you set 3. holistically you set 1.
that said I am pretty sure if you do this enough you will see some patterns emerge.
Try this problem. I give you a starting number and a goal number and also the number x.
E.g.:
start = 5
goal = 15
x = 7
The way you use the number x is by considering how it can be partitioned:
Diff
7 = 7 + 0 7
= 6 + 1 5
= 5 + 2 3
= 4 + 3 1
The diff column indicates how much you can add to start at a time.
Can we reach the goal? If not, how close can you get?
5 + 7 + 3 = 15 = goal
So we can reach the goal.
Notice that if x is odd we can always reach the goal. Since two odds sum to an even we can add in even amounts as well as odd amounts to reach any goal.
still stuck lame?
Duthomhas answered so I will give you a few more hints.
if you had 8 bits, and you can flip any 1 per iteration, you know you can solve it. Why?
if you had 8 bits, and you must flip 8 bits per go, you know that there are only 2 answers and the only way you can set all the bits is if the input number is binary zero or binary for 255. Why?
if you can flip 3 at a time, is there any pattern that you cannot convert to all 1s? why?
if you can flip 4 at a time, is there any pattern that you cannot convert to all 1s? why?
for flipping 5 or more at a time, are there inputs that cannot reach 255? This should be obvious by now if you got the above whys.
then you can get into, what you should be seeing here, is how many bits cannot be set for the ones where you cannot set them all to 1s, and how that is related to the # of bits you can flip..
this is going to start to resemble one of those swindler's games that people use to take their drunk friend's money ... ive got 8 packets of sugar here on the table, some facing up and some facing down... blah blah if you can get them all facing up by doing this... loser buys next round...