Reputation: 47
static string ReturnValueIfInputOneIsThree(string inputOne, string input)
{
string result = "";
if (CheckIfInputOneIsInACorrectFormatOrNot(inputOne, input) && inputOne == "3")
{
for (var i = 0; i < input.Length; i++)
{
if (input[i] == '0')
{
result += "1";
}
else if (input[i] == '1')
{
result += "0";
}
}
var finalResult = Convert.ToIn64(result, 2);
return finalResult.ToString();
}
return ThisReturnValuInMain(inputOne, input);
}
If I introduce a number in base 2 and I apply the not operator, for example ~00110001 or ~10 , I got the correct result, but when I Introduce a very large binary number like:
1011111111000000000011111111110000000000111111111100000000001111111111 the result is not “100000000111111111100000000001111111111000000000011111111110000000000”.
I tried to use BigInteger, but the module from the course doesn't let me to use it, so I have to solve the problem in another way.
Do you have any suggestion how to solve this problem without BigInteger?
Upvotes: 0
Views: 106
Reputation: 7960
The problem lies with
1011111111000000000011111111110000000000111111111100000000001111111111
Being 71 bits, and you're doing Convert.ToIn64(result, 2);
, which is cutting it down to 64 bits. If the input and output are both strings, then why even do the conversion to an Int64 (a long
)? Instead just return result
Edit: Just saw Lasse V. Karlsen's comment which basically says the same
Upvotes: 0