Summary of interview questions-bit

Source: Internet
Author: User
Tags bitset bitwise operators

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 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: with a space to store large numbers of detailed questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.