1. Assuming x=500, the return value of the following function is6_ .
12345678910 |
int fun(
int x)
{
int countx = 0;
while (x)
{
countx++;
x = x & (x – 1);
}
return countx;
}
|
Parsing:x& (x-1) is the first 1 that is encountered from right to left (including 1) all becomes 0, more intuitive: it results in a reduction of 1 in the X-binary. Answer: How many bits in x binary 1 will be performed and calculated.
The binary representation of 500 is: 111110100, a total of 6 1. So the answer is 6. 2. There are two n*n matrices A and B, want to be on the PC by the matrix multiplication basic algorithm programming realization computation a*b. Assuming that n is large and the native memory is large, a, B, and result matrices can be saved. So, in order to calculate the speed, how a and B should be stored in memory (the first row is stored by the row, then the second line, until the last row, the first column is stored first, then the second column, and then the last column)? are saved as rows.
Algorithm Pen Questions