Hi,
There is no need to set the 4th bit with 3 ones....
Let me give the complete detail for setting 7th bit with 3 ones.
 
Start: 0000000
 
Step 1. Use first n-1 (3-1) ones to reach 2^(3-1) - 1
 
1000000
1100000
0100000
0110000
 
Step 2: Set 2^(n-1)th bit (that is 4th bit) to one
 
0111000
 
Step 3: Reverse the first step.
 
0101000   
1101000
1001000
0001000
 
Step 4: Now use the n-1 (3-1) ones to set the next 2^(3-1) - 1 ones!
 
0001100
0001110
0001010
0001011
 
Now the 7th bit is set!
 
Regards,
Prunthaban

Reply via email to