• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            旅途

            如果想飛得高,就該把地平線忘掉

            面試系列1--返回整數(shù)中為1的位數(shù)

            ?原題:

            ? Write the function int bitCount(short input) that takes a short as input and
            ? returns an int.? The function returns the number of bits set in the input
            ? variable.? For instance:
            ? bitCount(7) --> 3
            ? bitCount(2543) --> 9
            ? bitCount(11111) --> 9

            代碼:

            /********************************************************************
            ??? created:??? 2006/06/14
            ??? created:??? 14:6:2006?? 16:53
            ??? filename:?? C:\Documents and Settings\Administrator\My Documents\近期閱讀\myTinyThing\bitCount.c
            ??? file path:? C:\Documents and Settings\Administrator\My Documents\近期閱讀\myTinyThing
            ??? file base:? bitCount
            ??? file ext:?? c
            ??? author:???? A.TNG
            ??? version:??? 0.0.1
            ???
            ??? purpose:??? 面試題
            ??????????????? Write the function int bitCount(short input) that takes a short as input and
            ??????????????? returns an int.? The function returns the number of bits set in the input
            ??????????????? variable.? For instance:
            ??????????????? bitCount(7) --> 3
            ??????????????? bitCount(2543) --> 9
            ??????????????? bitCount(11111) --> 9
            *********************************************************************/
            #include <stdio.h>

            /*
            ?*? name: bitCount
            ?*? params:
            ?*??? input???????? [in]??????? 需要分析的 short 型數(shù)
            ?*? return:
            ?*??? 輸入?yún)?shù) input 的為1的位數(shù)
            ?*? notes:
            ?*??? 計(jì)算 input 中為1的位數(shù)
            ?*? author: A.TNG 2006/06/14 17:00
            ?*/
            int bitCount(short input)
            {
            ??? int n_ret?? = 0;

            ??? /* 只要 input 不為0,則循環(huán)判斷 */
            ??? while (0 != input)
            ??? {
            ??????? /* 如果 input & 1 == 1 則表示最低位為1,反之則等于0 */
            ??????? if (input & 1)
            ??????? {
            ??????????? n_ret++;
            ??????? }
            ??????? input = input >> 1;
            ??? }

            ??? return n_ret;
            }

            /*
            ?*? name: main
            ?*? params:
            ?*??? none
            ?*? return:
            ?*??? 函數(shù)返回狀態(tài)給系統(tǒng)
            ?*? notes:
            ?*??? 系統(tǒng) main 函數(shù)
            ?*? author: A.TNG 2006/06/14 17:04
            ?*/
            int main()
            {
            ??? /* 輸入需要計(jì)算的整數(shù) */
            ??? int n?? = 2543;

            ??? /* 輸出 bitCount 的結(jié)果 */
            ??? printf("%d\n", bitCount((short) n));

            ??? /* 發(fā)送 PAUSE 命令給系統(tǒng) */
            ??? system("PAUSE");
            }

            posted on 2007-09-05 01:14 旅途 閱讀(122) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C/C++

            伊人久久精品影院| 精品久久久久久亚洲精品| 久久久久久久久久免免费精品| 久久精品国产亚洲AV香蕉| 久久久久九九精品影院| 久久精品视频免费| 91麻豆精品国产91久久久久久 | 精品久久久久久国产| 午夜精品久久影院蜜桃| 亚洲欧美国产精品专区久久| 亚洲国产成人久久综合野外| 久久免费观看视频| 久久人人青草97香蕉| 色狠狠久久综合网| 亚洲综合伊人久久综合| 欧美精品久久久久久久自慰| 久久99国产精品尤物| 日本三级久久网| 欧美国产成人久久精品| 亚洲精品tv久久久久| 模特私拍国产精品久久| 99久久做夜夜爱天天做精品| 久久综合香蕉国产蜜臀AV| 久久精品国产91久久综合麻豆自制 | 少妇被又大又粗又爽毛片久久黑人 | 久久亚洲中文字幕精品有坂深雪| 亚洲AV日韩精品久久久久久 | 久久99国产精品尤物| 精品国产乱码久久久久久浪潮| 久久久久97国产精华液好用吗| 伊人久久精品影院| 2020最新久久久视精品爱| 93精91精品国产综合久久香蕉| 欧美激情精品久久久久久久| 久久亚洲精品国产亚洲老地址| 久久久综合九色合综国产| 色偷偷88欧美精品久久久| 国产精品99久久免费观看| 久久九九免费高清视频| 伊人久久大香线蕉亚洲| 66精品综合久久久久久久|