问题描述
static string ReturnValueIfInputOneIsThirteenAndInputLengthIsEqualWithInputTwoLength(string input,string inputTwo)
{
string result = "";
int temp = 0;
int inputLength = input.Length - 1;
int inputTwoLength = inputTwo.Length - 1;
const int two = 2;
while (inputLength >= 0 || inputTwoLength >= 0 || temp > 0)
{
temp += (inputLength >= 0) ? input[inputLength] - '0' : 0;
temp += (inputTwoLength >= 0) ? inputTwo[inputTwoLength] - '0' : 0;
result = (char)(temp % two + '0') + result;
temp /= two;
inputLength--;
inputTwoLength--;
}
return result.Trimstart('0');
}
我必须以某种方式模拟两个以字符串表示的二进制数的减法运算符。所以我要求提供一个建议,在不将它们转换为整数的情况下实现这一点。
例如,如果我输入 101 和 11,结果应该是 10。
这就是我做加法的方式,但我找不到解决方案。
您有什么建议吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)