This function will count the number of 1's in the binary representation of a two's complement integer. For example the number 15 in binary is written as 1111; this contains four 1s. Or 33 is represented as 100001 and contains two 1's. SQL Server's data types do not include "unsigned-integer" so this alogrithm has been designed to also count the left most 1 in the Two's Complement representation of negative numbers.
It works by using the fact that when you subtract 1 from a binary number the right most 1 becomes zero and all leading zeros become 1. e.g.
00011110000 - 1 = 00011101111
Then a bitwise AND is done on the orginal number and the result
00011110000 & 00011101111 = 0001110000
This gives a result with one less 1 in.
The process is repeated until the result is zero. This takes as many operations as there are 1's in the original number so it is efficient when 1's are sparse in the bigint.