首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

二进制转换有关问题

2012-01-26 
二进制转换问题string str 0010101010,0101101001,0010101010string[] temp str.Split(,)int re

二进制转换问题
string str = "0010101010,0101101001,0010101010";
  string[] temp = str.Split(',');
  int result = 0;
  for (int i = 0; i < temp.Length; i++)
  {
  result |= Convert.ToInt32(temp[i], 2);
  }
  Console.WriteLine(Convert.ToString(result, 2));
/*
输出:
111101011
小了1位
我想要的结果是10位不变的,不够就前面补0如:0111101011,如何改上面的代码阿?


[解决办法]
Console.WriteLine(Convert.ToString(result, 2).PadLeft(10,'0'));

热点排行