You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Returns the number of ones in the binary representation of the decimal
147
147
// number.
148
148
functioncountBinaryOnes(n){
149
-
letcount=0;
150
-
// Remove one "1" bit from n until n is the power of 2. This iterates k times
151
-
// while k is the number of "1" in the binary representation.
152
-
// For more check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
153
-
while(n!==0){
154
-
n=n&(n-1);
155
-
count++;
156
-
}
157
-
returncount;
149
+
// Count the number of bits set in parallel, which is faster than looping
150
+
n=n-((n>>>1)&0x55555555);
151
+
n=(n&0x33333333)+((n>>>2)&0x33333333);
152
+
return((n+(n>>>4)&0xF0F0F0F)*0x1010101)>>>24;
158
153
}
159
154
160
-
functiongetCIDR({address, netmask, family}){
155
+
functiongetCIDR(address,netmask,family){
161
156
letones=0;
162
157
letsplit='.';
163
158
letrange=10;
@@ -193,17 +188,33 @@ function getCIDR({ address, netmask, family }) {
0 commit comments