From 86fb10a3344d96ddcfb9c16d0278b2e4304493a8 Mon Sep 17 00:00:00 2001 From: lLewdie Date: Fri, 22 Sep 2023 10:53:40 -0500 Subject: [PATCH] Binary to decimal & vice versa now works --- num-converter/WebForm1.aspx.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/num-converter/WebForm1.aspx.cs b/num-converter/WebForm1.aspx.cs index 4e06ed8..f08bcd6 100644 --- a/num-converter/WebForm1.aspx.cs +++ b/num-converter/WebForm1.aspx.cs @@ -16,7 +16,31 @@ namespace num_converter protected void btnConvert_Click(object sender, EventArgs e) { + String Result = string.Empty; + int Remainder; + int DecimalNum; + int BinaryNum; + int OctalNum; + int Base1 = 1; + + if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 2) + { + DecimalNum = Convert.ToInt32(txtInput.Text); + while (DecimalNum > 0) + { + Remainder = DecimalNum % 2; + DecimalNum /= 2; + Result = Remainder.ToString() + Result; + } + lblResult.Text = Result; + } + if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1) + { + BinaryNum = Convert.ToInt32(txtInput.Text, 2); + Result = BinaryNum.ToString(); + lblResult.Text = Result; + } } protected void btnClear_Click(object sender, EventArgs e)