src/misc.cpp
changeset 7375 e8639f73a615
parent 7139 4ae3ab180d05
child 7506 e52d89f5c7c1
equal deleted inserted replaced
7374:54c06f06ecc8 7375:e8639f73a615
   268 	if ((value & 0x00000001) == 0) { i += 1; }
   268 	if ((value & 0x00000001) == 0) { i += 1; }
   269 
   269 
   270 	return i;
   270 	return i;
   271 }
   271 }
   272 
   272 
       
   273 int CountBitsSet(uint32 value)
       
   274 {
       
   275 	int num;
       
   276 
       
   277 	/* This loop is only called once for every bit set by clearing the lowest
       
   278 	 * bit in each loop. The number of bits is therefore equal to the number of
       
   279 	 * times the loop was called. It was found at the following website:
       
   280 	 * http://graphics.stanford.edu/~seander/bithacks.html */
       
   281 
       
   282 	for (num = 0; value != 0; num++) {
       
   283 		value &= value - 1;
       
   284 	}
       
   285 
       
   286 	return num;
       
   287 }
   273 
   288 
   274 static void Save_NAME()
   289 static void Save_NAME()
   275 {
   290 {
   276 	int i;
   291 	int i;
   277 
   292