• <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>
            隨筆 - 62  文章 - 96  trackbacks - 0
            <2007年7月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(7)

            隨筆分類(66)

            隨筆檔案(62)

            文章分類(31)

            文章檔案(32)

            友情鏈接

            最新隨筆

            積分與排名

            • 積分 - 235712
            • 排名 - 108

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            #include<cstdlib>
            #include<cstdio>
            int main() { int num = 10; char str[100]; itoa(num, str, 2); printf("%s\n", str); return 0; }
            itoa()函數(shù)有3個(gè)參數(shù):第一個(gè)參數(shù)是要轉(zhuǎn)換的數(shù)字,第二個(gè)參數(shù)是目標(biāo)字符串,第三個(gè)參數(shù)是轉(zhuǎn)移數(shù)字時(shí)所用 的基數(shù)。在上例中,轉(zhuǎn)換基數(shù)為10。10:十進(jìn)制;2:二進(jìn)制……
            于是想到了一個(gè)十進(jìn)制轉(zhuǎn)二進(jìn)制的方法:
            #include<cstdlib>
            #include<cstdio>
            int main() { int num = 10; char str[100]; int n = atoi(itoa(num, str, 2)); printf("%d\n",n); return 0; }
            先把num轉(zhuǎn)換為二進(jìn)制的字符串,再把該字符串轉(zhuǎn)換為整數(shù)。
            posted on 2006-10-12 00:59 beyonlin 閱讀(67456) 評(píng)論(14)  編輯 收藏 引用 所屬分類: acm之路C++之路

            FeedBack:
            # re: itoa函數(shù) 2006-10-23 23:45 Asp
            感覺很容易越界吧……  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2006-10-24 00:33 beyonlin
            @Asp
            只是介紹一下STL函數(shù)的用法。
            那個(gè)str[100]只是一個(gè)例子~~  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2007-07-11 08:52 小文
            第二個(gè)參數(shù)用string類型,可以嗎?  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2007-07-11 09:49 AlanTop
            另一個(gè)10進(jìn)制轉(zhuǎn)二進(jìn)制的方法
            /*
            * 引用自 http://m.shnenglu.com/alantop/archive/2007/07/11/27845.html
            */
            // compile with: /EHsc
            #include
            #include

            int main( )
            {
            using namespace std;
            bitset<20> b1 ( 10 );
            cout << "The set of bits in bitset<5> b1( 10 ) is: ( "
            << b1 << " )." << endl;
            }
              回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2007-07-12 18:02 beyonlin
            @小文
            char* itoa(int, char*, int)
            第二個(gè)參數(shù)是char*,不能用string  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2007-12-19 16:12 sakar2003
            itoa只是WINDOWS下面才有的函數(shù)吧,UNIX下面是沒有itoa的,跨平臺(tái)還是sprintf好  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2008-08-01 11:33 sheena
            怎么第二個(gè)函數(shù)無法編譯呢。?
            int n = atoi(itoa(num, str, 2));

            n是不是還是應(yīng)該是當(dāng)初num 10 的值啊  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2009-03-15 15:43 lai
            根本不是一回事。形似而質(zhì)不同。那樣轉(zhuǎn)換n的值都不在是10了。而是1010(十進(jìn)制)  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2009-06-10 19:49 heh
            同意樓上。樓主水平確實(shí)不咋的  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2009-10-28 10:22 snhnbn
            呵呵,太搞笑的十進(jìn)制轉(zhuǎn)二進(jìn)制了。莫非是二進(jìn)制的BCD碼?  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2011-06-22 16:17 mxx
            @sheena
            絕對(duì)不是  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2011-06-22 16:18 mxx
            樓主這個(gè)是在拋磚引玉,樓主自己寫出來的程序,他能不調(diào)試一下敢貼上來?他是為了讓大家思考,你看函數(shù)的參數(shù)描寫的多好!  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2011-06-30 11:53 beyonlin
            @mxx
            謝謝你!  回復(fù)  更多評(píng)論
              
            # re: itoa函數(shù) 2012-11-29 17:54 腳步
            我用的是codeblocks的編譯器,為什么我的編譯器里沒有itoa函數(shù)?  回復(fù)  更多評(píng)論
              
            久久丝袜精品中文字幕| 久久综合狠狠色综合伊人| 性做久久久久久久久久久| 大香伊人久久精品一区二区| 国产精品久久久久久久人人看 | 天天久久狠狠色综合| 国产精品久久自在自线观看| 久久精品国产久精国产| 91精品国产91久久久久久青草| 久久久网中文字幕| 久久国产欧美日韩精品| 久久久久综合中文字幕| 国产欧美一区二区久久| 一本色道久久88综合日韩精品| 久久综合亚洲欧美成人| 久久久精品人妻无码专区不卡 | 2022年国产精品久久久久| 亚洲国产高清精品线久久| 久久亚洲国产精品一区二区| 久久久国产打桩机| 久久九色综合九色99伊人| 久久精品国产91久久综合麻豆自制| 婷婷久久综合九色综合绿巨人| 久久99精品国产99久久| 一本久久知道综合久久| 久久国产精品无| 国产成人AV综合久久| 97久久超碰国产精品2021| 精品免费久久久久久久| 亚洲成色www久久网站夜月| 午夜精品久久影院蜜桃| 亚洲国产小视频精品久久久三级 | 久久99国产精品成人欧美| 国产精品久久永久免费| 99久久婷婷国产综合亚洲| 久久99亚洲网美利坚合众国| AAA级久久久精品无码片| 国产精品99久久99久久久| 狠狠干狠狠久久| 久久99国产精品成人欧美| 亚洲伊人久久综合影院|