1public class Solution {2// you need treat n as an unsigned value3public int reverseBits(int n) {4int mask = 0;5int smask = 0;6int j = 0;7int rev = 0;89// basically we are checking that the number is set bit or not10// if the number is set bit then we are appending that to our main answer i.e, rev11for (int i = 31; i >= 0; i--) {12mask = 1 << i;13if ((mask & n) != 0) {14smask = 1 << j;15rev = rev | smask;16}17j++;18}1920// Time Complexity : O(32 for int)21// Space Complexity : O(1)22return rev;23}24}