如何将10进制数字字符串转换成二进制字符串
如何将10进制数字字符串转换成二进制字符串,不是16进制,如15-〉1111,而不是
oxf。
如何将二进制字符串转换成10进制,如:11110000-〉(int)0xF0;
问题点数:50、回复次数:5Top
1 楼LesterYu(啸)回复于 2004-01-02 22:07:10 得分 5
先将字符串转换为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 余数。
Top
2 楼wd_318(饭加加)回复于 2004-01-02 22:22:43 得分 0
Decimal.GetBits
public static int[] GetBits(
decimal d
);Top
3 楼Fancimage(faci)回复于 2004-01-02 22:38:58 得分 15
string getBinString(int val)
{
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();
}Top
4 楼snewxf(心疤)回复于 2004-01-02 23:28:53 得分 10
this.textBox1.Text =Convert.ToString(15,2);
Top
5 楼snewxf(心疤)回复于 2004-01-02 23:40:43 得分 20
二进制:
this.textBox1.Text =Convert.ToString(15,2);
十六进制:
int temp = Convert.ToInt32("11110000",2);
this.textBox1.Text =Convert.ToString(temp,16);Top




