NOTES: Lowbit ()

Source: Internet
Author: User

Because Codeforces 437B this problem, contact to the lowbit.

Write the function First:

int lowbit (int  x) {    return x& (-x);}

And the definition given on the original topic:

Lowbit (x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) =2, lowbit(100012) = 12, lowbit (100002) = 100002 (binary representation).

Easy to understand, is the binary form from the right number to the first 1, the bit represents the power of 2.

The principle of the function is the complement of the computer, i.e. (assuming 8 bits)

1 &-1 0000 0001 & 1111 1111 = 1

4 &-4 0000 0100 & 1111 1100 = 2

5 &-5 0000 0101 & 1111 1011 = 1

NOTES: Lowbit ()

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.