C#GUI二进制

编程入门 行业动态 更新时间:2024-10-12 14:18:09
本文介绍了C#GUI二进制 - 和*。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,我是编程的新手,目前正在自学C#GUI atm。 如何在不使用padleft方法的情况下进行二进制减法和乘法? 我设法做二进制加法部分,并被告知我可以重复使用加法代码进行乘法。 NVM解决。

Hi guys, I'm kinda new to programming, currently self studying C# GUI atm. How do I do binary subtraction and multiplication without using padleft method? I managed to do the binary addition part and was told that I can reuse the addition code for multiplication. NVM solved.

推荐答案

首先,这是你在那里的一些奇怪的代码: First off, that is some odd code you have there: for (int i = textBox1.TextLength - 1; i < textBox2.TextLength - 1; i++) { num1 = "0" + textBox1.Text; }

那是做什么的? 它与以下相同: 因为循环内的代码不使用循环变量我,或更改除 num1 以外的任何其他值,它与没有循环相同 - 它只是加载相同的价值进入 num1 几次... 我可以看到你想要做什么,有点 - 但是假设num1中的每个字符都是零或一个(或者它不是二进制),结果怎么可能是三个?

What does that do? It's the same as: Since the code inside the loop doesn't use the loop variable i, or change anythign other than the num1 value, it's the same as not having a loop at all - it just loads teh same value into num1 several times... I can see what you are trying to do, sort of - but assuming that each character in num1 is zero or one (or it isn't binary) how can the result ever be three?

0 + 0 == 0 0 + 1 == 1 1 + 0 == 1 1 + 1 == 2

因此,主处理循环中的测试是......嗯。 ..odd。 在你尝试乘法之前我会解决这个问题! :笑: 忽略这一点:我忘记了随身携带! :O [/ edit] 所以,内循环会起作用 - 所以乘法很容易: 想想你是怎么教的做乘法:

So the testing in your main processing loop is...um...odd. I'd sort that out before you try to get to multiplication! :laugh: [edit]Ignore that: I forgot the carry! :O [/edit] So, the inner loop will work - so multiplication is pretty easy: Think how you were taught to do multiplication:

7 * 5 == 7 + 7 + 7 + 7 + 7

然后为更高级的用户有很长的mutiplication: 123 * 45 --- 4920 +615 ---- 5535

Then for more advanced users there is long mutiplication: 123 *45 --- 4920 +615 ---- 5535

这会将你的两个二进制字符串转换成整数,你然后可以减去,并将其转换回二进制字符串 This will convert your two binary strings to integers, you can then subtract, and return it converted back to a binary string int i = Convert.ToInt32(textBox1.Text, 2); int j = Convert.ToInt32(textBox2.Text, 2); Return Convert.ToString(i - j, 2);

更多推荐

C#GUI二进制

本文发布于:2023-11-12 11:05:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!