Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

binary gap

function binaryGap(N) {
    const bin = (N >>> 0).toString(2);
    const gap = bin.substring(0, bin.lastIndexOf('1'));
    const arr = substr.split('1');
    return arr.sort().reverse()[0].length;
}

binaryGap(1041);
 
PREVIOUS NEXT
Tagged: #binary #gap
ADD COMMENT
Topic
Name
3+6 =