Today, I read the beauty of programming, and I saw the handsome question. After reading the answer, I felt that it was really fierce to go to Microsoft, I always like to do some bit-level operations on the interview questions, so I just want to summarize it for the sake of time. Hope you can help others.
Now everyone is interested in doing something on the shelf.Article, From the simplest shift operations faster than multiplication 2, to the advanced bit map method to solve the big data volume problem; from the high-level bitset encapsulation class one by one bitmap method sorting, to the CPU size end of the underlying programming, I feel that there are a lot of things that can be done on bit during the interview.
First of all, some of the bit operation questions can refer to the http://www.chinazk.com/bbs/dispbbs.asp? Boardid = 109 & id = 34801, which describes in detail the possible bit operations. Note the following two points:
1. The six bitwise operations provided by the C language can only be used for integer operations, that is, they can only be used for char, short, Int, and long types.
2. bitwise operators have lower priority than = and! =, Remember to add () during the test ()
Then there is the handsome question mentioned in the beauty of programming (Baidu can be used for details). After reading the three solutions provided by Microsoft and getting the questions, I first thought of a direct two-layer for loop, however, two int types are introduced, which does not meet the requirements of the question. They only have 1 byte space. Even if I use unsigned char in the loop (why is it unsigned?), it would take 2 bytes, according to the prompt of solution 1, I first thought of bitset. Although bitset operations may be a little complicated, of course, the solution I provided in the book is really troublesome and I didn't see it.
The third solution is a bit field, which is a traditional programming method.
Struct {unsigned char a; unsigned char B;} I;
The second solution is a thief. We can use byte num = 81 For ing, so that I = num % 9, j = num/9 + 1. In this way, all the positions are mapped, I = 1 to 9, j = 1 to 9. Of course, you can only use num to use num % 9 and num/9 + 1.
In addition, you can refer to: http://www.cnblogs.com/steven_oyj/archive/2010/05/23/1741975.html with a space to store large numbers of detailed questions