C³ÌÐò£ºÈ·¶¨Ò»¸öÕûÊýµÄ¼ÆËã»úÄÚ²¿±íʾÖÐÓм¸¸ö"1"
/*
×¢Òâ²»¶ÏÓÒÒÆÅжÏ×îµÍλÊÇ1ÓжàÉÙ¸öµÄËã·¨ÊÇ´íÎóµÄ£¬
ÒòΪ¸ù¾ÝGNU C/C++µÄʵÏÖÀ´¿´£¬¸ºÊýÊÇ´ø·ûºÅÌî³ä½øÐÐÓÒÒƵģ¬ËùÒÔÈç¹ûÊǸºÊý£¬¸ÃËã·¨»áËÀÑ»·¡£
±äͨ°ì·¨£ºJava¿ÉÒÔÓÃ>>>Âß¼ÓÒÒÆλ²Ù×÷·û£¬C/C++¿ÉÒÔÇ¿ÖÆת»»³ÉÎÞ·ûºÅÕûÊýÔÙ´¦Àí
ÏÂÃæµÄ³ÌÐòÊÇÕý½â¡£ÆäÖÐnum &= (num - 1) »áÏû³ýnumµÄ×îСλÖõÄ"1"
*/
#include <stdio.h>
int numOnesInBinary(int num)
{
int numOnes = 0;
while (num != 0) {
num &= (num - 1);
numOnes++;
}
return numOnes;
}
int main()
{
printf("%d", numOnesInBinary(-1));
return 0;
}
Ïà¹ØÎĵµ£º
ÔÚC++ÖУ¬¹ØÓÚCPPµÄÍ·Îļþ»¥Ïà°üº¬µÄÎÊÌâºÜÈÃÈËÍ·ÌÛ£¬ÆäʵÎÒÃÇËÒ²²»Ô¸ÒâŪµÄ½á¹¹»ìÂÒ£¬ÄÑÒÔÀí½â£¬µ«ÓÐʱÓÖÊÇÓбØÐëµÄ¡£
¼Ù¶¨µ±Ç°ÓÐÁ½¸öÍ·Îļþ·Ö±ðΪ A.h ºÍ B.h£¬ÄÚÈÝ·Ö±ðÈçÏ£º
A.hÄÚÈÝΪ£º
#ifndef  ......
ÊÔÌâ5£º±àдһ¸öº¯Êý£¬×÷ÓÃÊÇ°ÑÒ»¸öchar×é³ÉµÄ×Ö·û´®Ñ»·ÓÒÒÆn¸ö¡£±ÈÈçÔÀ´ÊÇ“abcdefghi”Èç¹ûn=2£¬ÒÆλºóÓ¦¸ÃÊÇ“hiabcdefgh”
¡¡¡¡º¯ÊýÍ·ÊÇÕâÑùµÄ£º
//pStrÊÇÖ¸ÏòÒÔ'\0'½áβµÄ×Ö·û´®µÄÖ¸Õë
//stepsÊÇÒªÇóÒƶ¯µÄn
void LoopMove ( char * pStr, int steps )
{
¡¡//ÇëÌî³ä...
}
¡¡¡¡½ ......
ͻ񻣼
ÔÚѧϰlinuxÄں˴úÂ뼰һЩ¿ªÔ´Èí¼þµÄÔ´Â루È磺DirectFB£©£¬¾³£¿ÉÒÔ¿´µ½ÓйØ
__attribute__µÄÏà¹ØʹÓᣱ¾ÎĽáºÏ×Ô¼ºµÄѧϰ¾Àú£¬½ÏΪÏêϸµÄ½éÉÜÁË__attribute__
Ïà¹ØÓï·¨¼°ÆäʹÓá£
---------------------------------------------------------
ÉùÃ÷£º
´ËÎÄΪԴ´£¬»¶ÓתÔØ£¬×ªÔØÇë±£ÁôÈçÏÂÐÅÏ¢
& ......
externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©.
Ëü¸æËß±àÒëÆ÷£¬ÆäÉùÃ÷µÄº¯ÊýºÍ±äÁ¿¿ÉÒÔÔÚ±¾Ä£¿é»òÆäËüÄ£¿éÖÐʹÓá£
1¡£¶ÔÓÚextern±äÁ¿À´Ëµ£¬½ö½öÊÇÒ»¸ö±äÁ¿µÄÉùÃ÷£¬Æä²¢²»ÊÇÔÚ¶¨Òå·ÖÅäÄÚ´æ¿Õ¼ä¡£Èç¹û¸Ã±äÁ¿¶¨Òå¶à´Î£¬»áÓÐÁ¬½Ó´íÎó
2¡£Í¨³££¬ÔÚÄ£¿éµÄÍ·ÎļþÖжԱ¾Ä£¿éÌṩ¸øÆäËüÄ£¿éÒýÓõĺ¯ÊýºÍ ......