9.5-bit operation (iv)--explanation code (n& (n-1)) the specific meaning of ==0

Source: Internet
Author: User
Title: Explanation Code (n& (n-1)) ==0 specific meaning
1) (a&b) Meaning of ==0
The binary representation of A and B in the same location will never be 1.
2) N and n-1 if the least significant bit of n is 1, minus 1 is 0, the remainder is the same and does not meet the requirements. The least significant bit of n is 0, minus 1 o'clock, which must be lent 1 to the high.
3) (n& (n-1)) ==0 meaning the most significant bit of n is 1, and the remaining bits are 0. Therefore, the value of n is one of the 2 of the square. So,(n& (n-1)) ==0 check if n is a 2 (or check if n is 0

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

9.5-bit operation (iv)--explanation code (n& (n-1)) the specific meaning of ==0

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: info-contact@alibabacloud.com 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.