I should start by mentioning that I know Wei Cui posted something that will pass in another person's question, but if I just copy and paste that I won't be learning why my own code is not validating. I can't seem to find any of the listed requirements I'm not in line with, and it works for all values 1 through Integer.MAX_VALUE.
The strategy with my code here is:
1. Convert the binary representation to something of the format 0...01...1, where the left-most 1 is the same as the left-most one in

*number*. This is done by number = (number >> 1) | number, 32 times to make sure it covers any binary value. 2. Bitshift left and & 1, so that it's still of the form 0...01...1 but the right-most 0 has been turned into a 1 and the right-most 1 stays a 1. 3. Use ^ operator with that and the previous value 0...01...1, so that you get a number of the form 0...010...0, where the 1 is one place to the left of where it needs to be. 4. Bitshift back to the right to get it in the correct place and use & operator with Integer.MAX_VALUE to prevent the sign from changing ( I didn't use >>> operator here because it's not in the list of allowed operators)package com.codegym.task.task30.task3013;
/*
Bit operations
*/
public class Solution
{
public static void main(String[] args)
{
Solution solution = new Solution();
///int number = Integer.MAX_VALUE - 133;
int number = 5;
System.out.println(Integer.toString(number, 2));
String result = Integer.toString(solution.resetLowerBits(number), 2);
System.out.println(result);
}
public int resetLowerBits(int number)
{
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = (number >> 1) | number;
number = number ^ ((number << 1) | 1);
number = (number >> 1) & Integer.MAX_VALUE;
return number;
}
}

46743in binary is1011011010010111, if you turn on all the bits it would be1111111111111111. It looks like you figured this part out between lines 23-57. Let me suggest that you condense those lines logically: - if you shift once to the right and use OR you know that the top 2 bits are guaranteed to be on - therefore you can next shift right 2 times, use OR, then the top 4 bits are guaranteed to be on - repeat for 4, 8, then 16 Instead of the 32 lines of code above you can use this to condense it down to 5 lines #2 Next, doing a bit reverse (~) you end up with the exact opposite, so 1's become 0's and 0's become 1's. The binary1111111111111111becomes11111111111111110000000000000000. Figure out how to get here. #3 Now you just need to use logical AND and make sure that the bit you want on matches in both binary numbers. I will let you figure this part out.