You are viewing a single comment's thread. Return to all comments →
public static long flippingBits(long n) { long x = n,sum = 0; List<Integer> li = new ArrayList<>(); for(int i = 0; i < 32; i++){ li.add(1); } int z = 1; while(x > 0){ if(x%2 == 1){ li.set(li.size()-z, 0); } else { li.set(li.size()-z, 1); } x = x/2; z++; } while(li.size() > 0){ sum += Math.pow(2,li.size()-1)*li.remove(0); } return sum; //long l = 4294967295L; //return (l - n); }
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →