C#:10进制转2进制函数

简介:

 1 ExpandedBlockStart.gif ContractedBlock.gif /**/ /*******************************************
2InBlock.gif * 十进制转二进制函数
3ExpandedBlockEnd.gif *******************************************/

4 ExpandedBlockStart.gif ContractedBlock.gif public string dtb( string buf) dot.gif {
5InBlock.gifint[] temp= new int[20];
6InBlock.gifstring binary;
7InBlock.gifint val=0,i=0,j;
8InBlock.gif
9ExpandedSubBlockStart.gifContractedSubBlock.gif/**//*先将字符转化为十进制数*/
10ExpandedSubBlockStart.gifContractedSubBlock.giftrydot.gif{
11InBlock.gif val = Convert.ToInt32(buf);
12ExpandedSubBlockStart.gifContractedSubBlock.gif }
catchdot.gif{
13InBlock.gif val = 0;
14ExpandedSubBlockEnd.gif }

15InBlock.gif
16ExpandedSubBlockStart.gifContractedSubBlock.gifif(val==0) dot.gif{
17InBlock.gifreturn(val.ToString());
18ExpandedSubBlockEnd.gif }

19InBlock.gif
20InBlock.gif i=0;
21ExpandedSubBlockStart.gifContractedSubBlock.gifwhile(val!=0) dot.gif{
22InBlock.gif temp[i++]=val%2;
23InBlock.gif val/=2;
24ExpandedSubBlockEnd.gif }

25InBlock.gif
26InBlock.gif binary = "";
27InBlock.giffor(j=0;j<=i-1;j++)
28InBlock.gif binary += (char)(temp[i-j-1]+48);
29InBlock.gif
30InBlock.gifreturn(binary);
31ExpandedBlockEnd.gif }



本文转自suifei博客园博客,原文链接:http://www.cnblogs.com/Chinasf/archive/2005/04/22/143309.html,如需转载请自行联系原作者
相关文章
|
8月前
|
C#
C#基础之Main函数
C#基础之Main函数
53 0
|
MySQL 关系型数据库 数据库连接
[C#][MySql]统计数据表总行数函数--C#和MySQL开发
使用C#连接MySQL数据库,调用统计数据表总行数函数,C#同学看过来
2890 0
|
C#
C#抽象类与抽象方法--就是类里面定义了函数而函数里面什么都没有做的类
看一下代码应该就可以了 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class...
825 0
C# 从函数到委托
原文地址:http://bbs.csdn.net/topics/390784442 看这样的程序: C# code? 1 2 3 4 5 6 7 8 9 10 11 12 int sum = 0; for (int i = 1; i &lt;= 100; i++)
984 0
|
C#
【C#】Excel舍入函数Round、RoundUp、RoundDown的C#版
原文:【C#】Excel舍入函数Round、RoundUp、RoundDown的C#版 本人在C#中进行小数舍入的时候常常会怀念Excel中的Round、RoundUp、RoundDown这几个函数,原因就是后者“接地气”,比较符合俺小老百姓的舍入要求,啥“银行家舍入法”就让银行家用去吧。
1451 0
|
XML C# 数据格式
C#函数方法集
1、DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 currentTime=System.DateTime.
1011 0
|
1月前
|
C#
24. C# 编程:用户设定敌人初始血值的实现
24. C# 编程:用户设定敌人初始血值的实现
20 0
|
2月前
|
SQL 数据库连接 应用服务中间件
C#WinForm基础编程(三)
C#WinForm基础编程
77 0