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
144
144
// number.
145
145
functioncountBinaryOnes(n){
146
-
letcount=0;
147
-
// Remove one "1" bit from n until n is the power of 2. This iterates k times
148
-
// while k is the number of "1" in the binary representation.
149
-
// For more check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
150
-
while(n!==0){
151
-
n=n&(n-1);
152
-
count++;
153
-
}
154
-
returncount;
146
+
// Count the number of bits set in parallel, which is faster than looping
147
+
n=n-((n>>>1)&0x55555555);
148
+
n=(n&0x33333333)+((n>>>2)&0x33333333);
149
+
return((n+(n>>>4)&0xF0F0F0F)*0x1010101)>>>24;
155
150
}
156
151
157
-
functiongetCIDR({address, netmask, family}){
152
+
functiongetCIDR(address,netmask,family){
158
153
letones=0;
159
154
letsplit='.';
160
155
letrange=10;
@@ -190,17 +185,33 @@ function getCIDR({ address, netmask, family }) {
0 commit comments