{"size": 1103, "ext": "js", "max_stars_repo_path": "src/CodeLearn/plaintextCode/codesignal/theCore/021_rightmostZeroBit.js", "max_stars_repo_name": "MingjunGeng/Code-Knowledge", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/CodeLearn/plaintextCode/codesignal/theCore/021_rightmostZeroBit.js", "max_issues_repo_name": "MingjunGeng/Code-Knowledge", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/CodeLearn/plaintextCode/codesignal/theCore/021_rightmostZeroBit.js", "max_forks_repo_name": "MingjunGeng/Code-Knowledge", "max_forks_repo_forks_event_min_datetime": "2022-03-18T04:52:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T04:52:10.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 22.06, "max_line_length": 52, "alphanum_fraction": 0.4641885766}
console.log("------------Test start--------------")
// --- 021 > Second-Rightmost Zero Bit
function theCore_rightmostZeroBit (n) {
    return ~(n |= -~n) & -~n;
}
function pow (n){
    let ns = n.toString(2).split('')
    let count = 0
    let power = 0 
    // console.log(ns)
    for(let i=ns.length-1, j=1; i>=0; i--, j++){
        // console.log(i, ns[i])
        if(ns[i] == 0){
            
            count++;
            if(count === 2){ 
                // return 1 <<(i+1)
                power = 1 <<(i+1);
            }
        }
    }
    return power;
}
let n
// n = 37
n = 1073741824
console.log( theCore_rightmostZeroBit (n) )


/*
You have to get rid of the rightmost 0
To fill in the rightmost 0 with 1 using x | (x + 1)
    10111100  (x)
|   10111101  (x + 1)
    --------
    10111101
Isolate the new rightmost 0
To isolate it use ~x & (x + 1)
// now x is the value after step 1

    10111101  (x)
    --------
    01000010  (~x)
&   10111110  (x + 1)
    --------
    00000010
 in short 
  return ~(n|(n+1)) & ((n|(n+1))+1) ;
*/
console.log("------------Test   End---------------")