先将字符串转换为Decimal类型,再用Decimal 模数运算符取被2除后的余数,然后反顺排列就行了。p.s.
Decimal 模数运算符 [C#]
返回两个指定 Decimal 值相除所得的余数。
[C#]
public static decimal operator %(
decimal d1,
decimal d2
);
参数 [C#, C++]
d1
Decimal(被除数)。
d2
Decimal(除数)。
返回值
d1 除以 d2 所得的 Decimal 余数。
Decimal 模数运算符 [C#]
返回两个指定 Decimal 值相除所得的余数。
[C#]
public static decimal operator %(
decimal d1,
decimal d2
);
参数 [C#, C++]
d1
Decimal(被除数)。
d2
Decimal(除数)。
返回值
d1 除以 d2 所得的 Decimal 余数。
解决方案 »
- 方法的重写与重载有什么区别
- DataGridView单元格验证后显示ToolTip的问题
- Assembly.Load(Byte[])释放问题
- 如果抓取各大商场(京东,易讯,新蛋等)的商品价格?
- 想做个可视化的表间关系编辑工具给点意见!
- 请各位高手帮帮忙:怎样实现TreeView 的分级加载?(就象CSDN的树一样)
- 怎么定义用字符串索引的数组,使用方式是类似Session["username"]这样用。
- 再开一帖问个字符串的问题
- 怎样判断字符串里存的是英文还是中文,或者中英文都有?
- datagridview如何判断所有行其中一列的是否相等
- 求助,怎么再c#里面写sniffer程序
- 请教:用C#(ADO.NET或者OLEDB)来获得一个excel文件的一个表格中每个单元的值???
public static int[] GetBits(
decimal d
);
{
char[] chs=new char[]{'0','1'};
int s;//商
int y=val;//余数
System.Text.StringBuilder str=new System.Text.StringBuilder();
while(y>0)
{
s=y/2;//得到商
y=y%2;//得到余数
str.Insert(0,chs[y]);
if(s>=2)
{
y=s;
}
else
{
if(s>0) str.Insert(0,chs[s]);
y=0;
}
}
return str.ToString();
}
this.textBox1.Text =Convert.ToString(15,2);
十六进制:
int temp = Convert.ToInt32("11110000",2);
this.textBox1.Text =Convert.ToString(temp,16);