C + + about BITS Operations Summary

Source: Internet
Author: User

#include <iostream>using namespace STD;//BITS reverse order. intGrial (intx) {intn = +;intCount =0; while(n--) {count|= (x&0x1) << N); x = ((unsigned) x >>1); }returnCount;}intMain () {cout<< Grial (1) << Endl;return 0;}#include <iostream>using namespace STD;//Bits parity in the exchange. intGrial (intx) {intSUM1 = x &0x55555555;intsum2 = x &0xaaaaaaaa; Sum1 <<=1; Sum2 >>=1;returnsum1 | sum2;}intMain () {cout<< Grial (6) << Endl;return 0;}#include <iostream>using namespace STD;//Ask two number of the and.

intGrial (intXintY) {if(!y)returnX//int ret = x^y; //-1%2=-1; intsum = x^y;intnum = ((x&y) <<1);returnGrial (sum,num);}intMain () {cout<< Grial (3,5) << Endl;return 0;}#include <iostream>using namespace STD;//Infer that a number is not 2 of the n-th side. BOOLGrial (intx) {return(x& (X-1)) ==0;}intMain () {cout<< Grial (4) << Endl;return 0;}#include <iostream>using namespace STD;//Find the number of 1 in binary. intGrial (intx) {intCount =0; while(x) {x = x& (X-1); count++; }returnCount;}intMain () {cout<< Grial ( the) << Endl;}#include <iostream>using namespace STD;//averaging. intGrial (intXintY) {return(x&y) + ((x^y) >>1);}intMain () {cout<< Grial ( -, -) << Endl;return 0;}#include <iostream>using namespace STD;//averaging. intGrial (intXintY) {returnX-(XY)/2;}intMain () {cout<< Grial (3,9) << Endl;return 0;}

C + + about BITS Operations Summary

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.