Sunteți pe pagina 1din 21

Problema de rezolvat:

Extindeți aplicația implementată la pasul anterior. Să se implementeze


funcționalitatea de adunare a două numere binare.

Pe prima linie aplicația primește codul operației:


1 - conversie de la baza 10 la baza 2
2 - conversie de la baza 2 la baza 10
3 - aplicarea operatorului NOT pe numărul în baza doi primit
4 - aplicarea operatorului OR pentru două numere binare date
5 - aplicarea operatorului AND pentru două numere binare date
6 - aplicarea operatorului XOR pentru două numere binare date
7 - mutare la stânga (shift left) N poziții pentru un număr binar dat
8 - mutare la dreapta (shift right) N poziții pentru un număr binar dat
9 - compară două numere binare date (operatorul mai mic decât - less than)
10 - compară două numere binare date (operatorul mai mare decât - greater than)
11 - compară două numere binare date (operatorul egal - equal)
12 - compară două numere binare date (operatorul diferit - not equal)
13 - adună două numere binare

Pe următoarele linii sunt numărul sau numerele pentru care se execută operația
(câte un număr pe linie).

Exemplul 1:

Pentru datele de intrare:

13
10110
11
La consolă se va afișa:

11001
Exemplul 2:

Pentru datele de intrare:

13
10
10
La consolă se va afișa:

100

using System;

namespace Sudoku
{
class Program
{
static void Main()
{
string operation = Console.ReadLine();
int op;
bool isOpNumeric = int.TryParse(operation, out op);
if (!isOpNumeric)
{
Console.WriteLine("Operatie invalida.");
}
else
{
string inputdata = Console.ReadLine();
ulong n;
int x = 0;
int z = 0;
int y = 0;
bool isNumeric = ulong.TryParse(inputdata, out n);
if (!isNumeric)
{
x++;
}

Operations(op, n, ref x, inputdata, ref z, ref y);


while (z == 0 && x != 0)
{
Console.WriteLine("Programul converteste doar numere intregi
pozitive.");
z++;
}
}
}

private static void Operations(int op, ulong n, ref int x, string


inputdata, ref int z, ref int y)
{
const string notbinar = "Nu s-a introdus un numar binar valid (format
doar din 0 si 1).";
FromBase2And10(ref op, ref inputdata, ref y, ref z, notbinar, ref n,
ref x);
Not(ref op, ref inputdata, ref y, ref z, notbinar);
Or(ref op, ref inputdata, ref y, ref z, ref n, notbinar);
And(ref op, ref inputdata, ref y, ref z, ref n, notbinar);
Xor(ref op, ref inputdata, ref y, ref z, ref n, notbinar);
ShiftLeftRifght(ref op, inputdata, ref y, ref z, notbinar);
Comparison(ref op, inputdata, ref y, ref z, notbinar);
BinarSum(ref op, inputdata, ref y, ref z, notbinar);
while (x == 0 && z == 0 && y == 0)
{
Console.WriteLine("Operatie invalida.");
z++;
y++;
}
}

private static void FromBase2And10(ref int op, ref string inputdata, ref
int y, ref int z, string notbinar, ref ulong n, ref int x)
{
const int baseconvertor = 2;
int w = 0;
string binary = "";
x = 0;
foreach (char c in inputdata)
{
if (!(c >= '0' && c <= '9'))
{
x = 1;
}
}
while (op == 1 && x == 0)
{
if (n < 0)
{
Console.WriteLine("Programul converteste doar numere intregi
pozitive.");
x++;
z++;
}
else
{
binary = FromBase10(ref n, new[] { '0', '1' });
Console.WriteLine(binary);
x++;
z++;
}
}

while (op == baseconvertor && x == 0)


{
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
x++;
y++;
z++;
}
else
{
string dinbaza2 = Convert.ToInt64(inputdata,
baseconvertor).ToString();
Console.WriteLine(dinbaza2);
x++;
y++;
z++;
}
}
}

private static string FromBase10(ref ulong n, char[] baseChars)


{
string result = string.Empty;
ulong targetBase = (ulong)baseChars.Length;

do
{
result = baseChars[n % targetBase] + result;
n /= targetBase;
}
while (n > 0);

return result;
}

private static void Not(ref int op, ref string inputdata, ref int y, ref
int z, string notbinar)
{
int a = 3;
int w = 0;
while (op == a && z == 0)
{
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
JustOnes(inputdata, ref y, ref op, ref z, ref a);
}
}
}

private static void IsBaza2(string inputdata, ref int w)


{
int b = 2;
const int baza2 = 2;
const int c = 3;
while (b == baza2)
{
for (int i = 0; i < inputdata.Length; i++)
{
if (!(inputdata[i] >= '0' && inputdata[i] < ('0' + baza2)))
{
w++;
}
}

b = c;
}
}

private static void JustOnes(string inputdata, ref int y, ref int op, ref
int z, ref int a)
{
int just1 = 0;
for (int i = 0; i < inputdata.Length; i++)
{
if (inputdata.Contains("0"))
{
just1++;
}
}

if (just1 == 0)
{
Console.WriteLine("0");
op = a++;
z++;
}
else
{
char[] element = { '0' };
string str1 = inputdata;
string str2 = "";
for (int n = 0; n < str1.Length; ++n)
{
str2 += (~(str1[n] - '0')) & 0x01;
}

string final = str2.TrimStart(element);


y++;
op = a++;
z++;
Console.WriteLine(final);
}
}

private static void Or(ref int op, ref string inputdata, ref int y, ref int
z, ref ulong n, string notbinar)
{
int a = 4;
int w = 0;
while (z == 0 && op == a)
{
string secondnumber = Console.ReadLine();
IsBaza2(inputdata, ref w);
IsBaza2second(secondnumber, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
OrOperation(ref inputdata, ref secondnumber, ref n);
y++;
z++;
op = a++;
}
}
}

private static void IsBaza2second(string secondnumber, ref int w)


{
int b = 2;
const int baza2 = 2;
const int c = 3;
while (b == baza2)
{
for (int i = 0; i < secondnumber.Length; i++)
{
if (!(secondnumber[i] >= '0' && secondnumber[i] < ('0' +
baza2)))
{
w++;
}
}

b = c;
}
}

private static void OrOperation(ref string inputdata, ref string


secondnumber, ref ulong n)
{
int x = inputdata.Length - secondnumber.Length;
const string y = "0";
string inputsmal = inputdata;
string secondsmal = secondnumber;
int i = 0;
int e = 0;
const int b = 2;
if (x < 0)
{
int w = x * -1;
while (i < w)
{
inputsmal = y + inputsmal;
i++;
}
}
else if (x > 0)
{
while (i < x)
{
secondsmal = y + secondsmal;
i++;
}
}

bool toLong = ulong.TryParse(inputsmal, out n);


if (toLong)
{
string inputsmal2 = Convert.ToInt32(inputsmal, b).ToString();
string secondsmal2 = Convert.ToInt32(secondsmal, b).ToString();
int inputsmalf = Convert.ToInt32(inputsmal2);
int secondsmalf = Convert.ToInt32(secondsmal2);
int orfinal = inputsmalf | secondsmalf;
string orfinalstr = Convert.ToString(orfinal);
bool isNumeric = ulong.TryParse(orfinalstr, out n);
string orfinalbinar = FromBase10(ref n, new[] { '0', '1' });
Console.WriteLine(orfinalbinar);
}
else
{
string final = "";
while (e < inputsmal.Length)
{
char[] ch = inputsmal.ToCharArray();
if (inputsmal[i] == 0 && secondsmal[i] == inputsmal[i])
{
ch[i] = '0';
string newstring = new string(ch);
e++;
}
else
{
ch[i] = '1';
string newstring = new string(ch);
e++;
final = newstring;
}
}

Console.WriteLine(final);
}
}

private static void And(ref int op, ref string inputdata, ref int y, ref
int z, ref ulong n, string notbinar)
{
int a = 5;
int w = 0;
while (z == 0 && op == a)
{
string secondnumber = Console.ReadLine();
IsBaza2(inputdata, ref w);
IsBaza2second(secondnumber, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
AndOperation(ref inputdata, ref secondnumber, ref n);
y++;
z++;
op = a++;
}
}
}

private static void AndOperation(ref string inputdata, ref string


secondnumber, ref ulong n)
{
int x = inputdata.Length - secondnumber.Length;
const string y = "0";
string inputsmal = inputdata;
string secondsmal = secondnumber;
int i = 0;
int e = 0;
const int b = 2;
if (x < 0)
{
int w = x * -1;
while (i < w)
{
inputsmal = y + inputsmal;
i++;
}
}
else if (x > 0)
{
while (i < x)
{
secondsmal = y + secondsmal;
i++;
}
}

bool toLong = ulong.TryParse(inputsmal, out n);


if (toLong)
{
string inputsmal2 = Convert.ToInt32(inputsmal, b).ToString();
string secondsmal2 = Convert.ToInt32(secondsmal, b).ToString();
int inputsmalf = Convert.ToInt32(inputsmal2);
int secondsmalf = Convert.ToInt32(secondsmal2);
int orfinal = inputsmalf & secondsmalf;
string orfinalstr = Convert.ToString(orfinal);
bool isNumeric = ulong.TryParse(orfinalstr, out n);
string orfinalbinar = FromBase10(ref n, new[] { '0', '1' });
Console.WriteLine(orfinalbinar);
}
else
{
string final = "";
char[] ch = inputsmal.ToCharArray();
while (e < inputsmal.Length)
{
if (inputsmal[i] == '1' && secondsmal[i] == inputsmal[i])
{
ch[i] = '1';
string newstring = new string(ch);
e++;
i++;
final = newstring;
}
else
{
ch[i] = '0';
string newstring = new string(ch);
e++;
i++;
final = newstring;
}
}

Console.WriteLine(final);
}
}

private static void Xor(ref int op, ref string inputdata, ref int y, ref
int z, ref ulong n, string notbinar)
{
int a = 6;
int w = 0;
while (z == 0 && op == a)
{
string secondnumber = Console.ReadLine();
IsBaza2(inputdata, ref w);
IsBaza2second(secondnumber, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
Xoroperation(ref inputdata, ref secondnumber, ref n);
y++;
z++;
op = a++;
}
}
}

private static void Xoroperation(ref string inputdata, ref string


secondnumber, ref ulong n)
{
int x = inputdata.Length - secondnumber.Length;
const string y = "0";
string inputsmal = inputdata;
string secondsmal = secondnumber;
int i = 0;
int e = 0;
const int b = 2;
if (x < 0)
{
int w = x * -1;
while (i < w)
{
inputsmal = y + inputsmal;
i++;
}
}
else if (x > 0)
{
while (i < x)
{
secondsmal = y + secondsmal;
i++;
}
}

bool toLong = ulong.TryParse(inputsmal, out n);


if (toLong)
{
string inputsmal2 = Convert.ToInt32(inputsmal, b).ToString();
string secondsmal2 = Convert.ToInt32(secondsmal, b).ToString();
int inputsmalf = Convert.ToInt32(inputsmal2);
int secondsmalf = Convert.ToInt32(secondsmal2);
int orfinal = inputsmalf ^ secondsmalf;
string orfinalstr = Convert.ToString(orfinal);
bool isNumeric = ulong.TryParse(orfinalstr, out n);
string orfinalbinar = FromBase10(ref n, new[] { '0', '1' });
Console.WriteLine(orfinalbinar);
}
else
{
string final = "";
i = 0;
char[] ch = inputsmal.ToCharArray();
while (e < inputsmal.Length)
{
if (inputsmal[i] != secondsmal[i])
{
ch[i] = '1';
string newstring = new string(ch);
e++;
i++;
final = newstring;
}
else
{
ch[i] = '0';
string newstring = new string(ch);
e++;
i++;
final = newstring;
}
}

Console.WriteLine(final);
}
}

private static void ShiftLeftRifght(ref int op, string inputdata, ref int
y, ref int z, string notbinar)
{
int shiftleft = 7;
const int shiftright = 8;
int w = 0;
while (z == 0 && op == shiftleft || op == shiftright)
{
while (z == 0)
{
string shiftvalue = Console.ReadLine();
bool isInteger = int.TryParse(shiftvalue, out var result);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
op = shiftleft--;
}

if (!isInteger)
{
Console.WriteLine("Numarul de pozitii trebuie sa fie intreg
si pozitiv.");
y++;
z++;
op = shiftleft--;
}
else if (result < 0)
{
Console.WriteLine("Numarul de pozitii trebuie sa fie intreg
si pozitiv.");
z++;
op = shiftleft--;
}

if (z == 0)
{
ShiftOperation(inputdata, shiftvalue, shiftleft,
shiftright, op);
y++;
z++;
op = shiftleft--;
}
}
}
}

private static void ShiftOperation(string inputdata, string shiftvalue, int


shiftleft, int shiftright, int op)
{
int shiftvalueint = Convert.ToInt32(shiftvalue);
string addzero = "";
int i = 0;
while (op == shiftleft && i == 0)
{
while (i < shiftvalueint)
{
addzero += "0";
i++;
}

Console.WriteLine(inputdata + addzero);
}

while (op == shiftright && i == 0)


{
string stringsum = "";
char[] element = { '0' };
while (i < shiftvalueint)
{
addzero += "0";
i++;
}

if (shiftvalueint > inputdata.Length)


{
Console.WriteLine("0");
}
else
{
stringsum = addzero + inputdata;
string shiftresult = stringsum.Substring(0, inputdata.Length);
string final = shiftresult.TrimStart(element);
Console.WriteLine(final);
}
}
}

private static void Comparison(ref int op, string inputdata, ref int y, ref
int z, string notbinar)
{
const string falseresult = "False";
const string trueresult = "True";
Lessthan(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
GreaterThan(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
Equal(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
NotEqual(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
}

private static void Lessthan(ref int op, string inputdata, ref int y, ref
int z, string notbinar, string falseresult, string trueresult)
{
int lessthan = 9;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == lessthan)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}

if (inputnozero.Length != secondnozero.Length)
{
if (inputnozero.Length > secondnozero.Length)
{
z++;
y++;
op = lessthan--;
Console.WriteLine(falseresult);
}
else
{
z++;
y++;
op = lessthan--;
Console.WriteLine(trueresult);
}
}
else if (z == 0)
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = lessthan--;
}
}
}
private static void GreaterThan(ref int op, string inputdata, ref int y,
ref int z, string notbinar, string falseresult, string trueresult)
{
int greaterthan = 10;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == greaterthan)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}

if (inputnozero.Length != secondnozero.Length)
{
if (inputnozero.Length > secondnozero.Length)
{
z++;
y++;
op = greaterthan--;
Console.WriteLine(trueresult);
}
else
{
z++;
y++;
op = greaterthan--;
Console.WriteLine(falseresult);
}
}
else
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = greaterthan--;
}
}
}

private static void Equal(ref int op, string inputdata, ref int y, ref int
z, string notbinar, string falseresult, string trueresult)
{
int equal = 11;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == equal)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}
else
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = equal--;
}
}
}

private static void NotEqual(ref int op, string inputdata, ref int y, ref
int z, string notbinar, string falseresult, string trueresult)
{
int notequal = 12;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == notequal)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}
else
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = notequal--;
}
}
}

private static void EqualNumbers(string inputnozero, string secondnozero,


int op, string falseresult, string trueresult)
{
string first = inputnozero;
string second = secondnozero;
int lessthan = 9;
int greaterthan = 10;
int equal = 11;
int notequal = 12;
while (op == lessthan)
{
EqualNumbersLess(first, second, inputnozero, falseresult,
trueresult);
op = lessthan--;
}

while (op == greaterthan)


{
EqualNumbersGreater(first, second, inputnozero, falseresult,
trueresult);
op = greaterthan--;
}

while (op == equal)


{
EqualNumbersEqual(first, second, inputnozero, falseresult,
trueresult);
op = equal--;
}

while (op == notequal)


{
EqualNumbersNotEqual(first, second, inputnozero, falseresult,
trueresult);
op = notequal--;
}
}

private static void EqualNumbersLess(string first, string second, string


inputnozero, string falseresult, string trueresult)
{
for (int i = 0; i < inputnozero.Length; i++)
{
if (first[i] == '0' && second[i] == '1')
{
Console.WriteLine(trueresult);
break;
}

if (first[i] == '1' && second[i] == '0')


{
Console.WriteLine(falseresult);
break;
}

if (i == inputnozero.Length - 1)
{
Console.WriteLine(falseresult);
}
}
}

private static void EqualNumbersGreater(string first, string second, string


inputnozero, string falseresult, string trueresult)
{
for (int i = 0; i < inputnozero.Length; i++)
{
if (first[i] == '0' && second[i] == '1')
{
Console.WriteLine(falseresult);
break;
}

if (first[i] == '1' && second[i] == '0')


{
Console.WriteLine(trueresult);
break;
}

if (i == inputnozero.Length - 1)
{
Console.WriteLine(falseresult);
}
}
}

private static void EqualNumbersEqual(string first, string second, string


inputnozero, string falseresult, string trueresult)
{
for (int i = 0; i < inputnozero.Length; i++)
{
if (first[i] == '0' && second[i] == '1')
{
Console.WriteLine(falseresult);
break;
}

if (first[i] == '1' && second[i] == '0')


{
Console.WriteLine(falseresult);
break;
}

if (i == inputnozero.Length - 1)
{
Console.WriteLine(trueresult);
}
}
}

private static void EqualNumbersNotEqual(string first, string second,


string inputnozero, string falseresult, string trueresult)
{
for (int i = 0; i < inputnozero.Length; i++)
{
if (first[i] == '0' && second[i] == '1')
{
Console.WriteLine(trueresult);
break;
}

if (first[i] == '1' && second[i] == '0')


{
Console.WriteLine(trueresult);
break;
}

if (i == inputnozero.Length - 1)
{
Console.WriteLine(falseresult);
}
}
}

private static void BinarSum(ref int op, string inputdata, ref int y, ref
int z, string notbinar)
{
int binarsum = 13;
int w = 0;
int k = 0;
while (z == 0 && op == binarsum)
{
while (z == 0)
{
string secondnumber = Console.ReadLine();
secondnumber = secondnumber.Replace(" ", "");
inputdata = inputdata.Replace(" ", "");
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
k = w;
op = binarsum--;
}

IsBaza2second(secondnumber, ref w);


if (k == 0 && w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
op = binarsum--;
}

if (z == 0)
{
BinarSumOperation(inputdata, secondnumber);
y++;
z++;
op = binarsum--;
}
}
}
}

private static void BinarSumOperation(string inputdata, string


secondnumber)
{
long secondnumberzero = 0;
long inputdatazero = 0;
int i = 0;
string addspace = "";
string carryover = "0";
string newsecondnumber = secondnumber;
string newinputdata = inputdata;
string result = "";
string final = "0";
if (inputdata.Length > secondnumber.Length)
{
secondnumberzero = inputdata.Length - secondnumber.Length;

while (i < secondnumberzero)


{
addspace = " ";
i++;
newsecondnumber = addspace + newsecondnumber;
}
}
else
{
inputdatazero = secondnumber.Length - inputdata.Length;

while (i < inputdatazero)


{
addspace += " ";
i++;
newinputdata = addspace + inputdata;
}
}

int j = newinputdata.Length - 1;
while (j >= 0)
{
if (carryover == "0")
{
Nocarryover(ref result, newsecondnumber, newinputdata, ref
carryover, j, ref final);
j--;
}

if (carryover == "1" && j >= 0)


{
Carryover(ref result, newsecondnumber, newinputdata, ref
carryover, j, ref final);
j--;
}
}

ResultLongerThanInputs(ref result, ref carryover, j, ref final);

Console.WriteLine(final);
}

private static void Nocarryover(ref string result, string newsecondnumber,


string newinputdata, ref string carryover, int j, ref string final)
{
long whilecontrol = 0;
long space = 0;
char[] zero = { '0' };
if (newinputdata[j] == ' ')
{
char element = newsecondnumber[j];
result = element + result;
carryover = "0";
whilecontrol = 1;
space++;
final = result.TrimStart(zero);
}

if (newsecondnumber[j] == ' ')


{
char element = newinputdata[j];
result = element + result;
carryover = "0";
whilecontrol = 1;
space++;
final = result.TrimStart(zero);
}

if (space == 0 && newinputdata[j] != newsecondnumber[j])


{
const string element = "1";
result = element + result;
carryover = "0";
whilecontrol = 1;
final = result.TrimStart(zero);
}

while (whilecontrol == 0)
{
if (newinputdata[j] == '0')
{
const string element = "0";
result = element + result;
carryover = "0";
whilecontrol++;
final = result.TrimStart(zero);
}

if (newinputdata[j] == '1')
{
const string element = "0";
result = element + result;
carryover = "1";
whilecontrol++;
final = result.TrimStart(zero);
}
}
}

private static void Carryover(ref string result, string newsecondnumber,


string newinputdata, ref string carryover, int j, ref string final)
{
long whilecontrol = 0;
long space = 0;
char[] zero = { '0' };
if (newinputdata[j] == ' ')
{
if (newsecondnumber[j] == '0')
{
char element = carryover[0];
result = element + result;
carryover = "0";
whilecontrol = 1;
space++;
final = result.TrimStart(zero);
}
else
{
const char element = '0';
result = element + result;
carryover = "1";
whilecontrol = 1;
space++;
final = result.TrimStart(zero);
}
}

if (newsecondnumber[j] == ' ')


{
if (newinputdata[j] == '0')
{
char element = carryover[0];
result = element + result;
carryover = "0";
whilecontrol = 1;
space++;
final = result.TrimStart(zero);
}
else
{
const char element = '0';
result = element + result;
carryover = "1";
whilecontrol = 1;
space++;
final = result.TrimStart(zero);
}
}

if (space == 0 && newinputdata[j] != newsecondnumber[j])


{
const string element = "0";
result = element + result;
carryover = "1";
whilecontrol = 1;
final = result.TrimStart(zero);
}

while (whilecontrol == 0)
{
if (newinputdata[j] == '0')
{
const string element = "1";
result = element + result;
carryover = "0";
whilecontrol++;
final = result.TrimStart(zero);
}

if (newinputdata[j] == '1')
{
const string element = "1";
result = element + result;
carryover = "1";
whilecontrol++;
final = result.TrimStart(zero);
}
}
}

private static void ResultLongerThanInputs(ref string result, ref string


carryover, int j, ref string final)
{
char[] zero = { '0' };
while (j == -1 && carryover == "1")
{
const char element = '1';
result = element + result;
carryover = "0";
j--;
final = result.TrimStart(zero);
}
}
}
}

S-ar putea să vă placă și