Large numbers of hosts (/0 and /1 subnets) are overflowing and showing as a negative number. Changing 1<<(32-mask) to 2**(32-mask) causes JavaScript to calculate the integer properly.