2015 Millet Summer Internship Pen Question _ understand binary (bitwise operation)

Source: Internet
Author: User

A total of 3 questions, the last is not AC out ...


There are 10 kinds of people in the world, one understands the binary system, one does not understand.
So you know the binary representation of two int32 integers m and n, how many bits are different?
Input Example:


1999 2299


Output Example:


7


This method is similar to the one seen in the beauty of programming.


Code:

#include <iostream>using namespace Std;int countbitdiff (int m, int n) {int sum=0;for (int i=0;i<32;i++) if (m> >i & 0x1)! = (N>>i & 0x1)) Sum++;return sum;} int main () {int N,m;cin>>n>>m;cout<<countbitdiff (n,m) <<endl;return 0;}




2015 Millet Summer Internship Pen Question _ understand binary (bitwise operation)

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.