vs c# 中二进制数相加的代码

来源:百度知道 编辑:UC知道 时间:2024/09/21 08:10:37
在textbox1和textbox2中分别输入二进制字符串,将它们相加的结果在textbox3中显示怎么代码怎么写啊?

希望你能从中得到你想要的吧! 对你有用的话,加分啊!!

using System;
using System.Collections.Generic;
using System.Text;

namespace 二进制转换
{
class Program
{
static void Main(string[] args)
{
int mark = 119;
int tem = ToErJin(mark);
Console.WriteLine("转成二进制后:"+tem);

int mark2 = 111;
int tem2 = ToShijin(mark2);
Console.WriteLine("转成十进制后:"+tem2);
}
public static int ToErJin(int value)
{
int temp = 0;
int shang=1;
int yushu;
while(shang!=0){
shang = (int)value / 2;
yushu = value % 2;
value = shang;
temp += yushu;
if(shang!=0){
temp = temp * 10;}
}
return temp;