From f3a53bcbc0538ec531c02cfe67e1ab5b1f341b64 Mon Sep 17 00:00:00 2001 From: lLewdie Date: Fri, 22 Sep 2023 17:07:14 -0500 Subject: [PATCH] The rest should be done --- num-converter/WebForm1.aspx | 2 + num-converter/WebForm1.aspx.cs | 71 ++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/num-converter/WebForm1.aspx b/num-converter/WebForm1.aspx index ef8075a..f55204c 100644 --- a/num-converter/WebForm1.aspx +++ b/num-converter/WebForm1.aspx @@ -48,6 +48,8 @@ Select An Option Decimal Binary + Octal + Hexadecimal diff --git a/num-converter/WebForm1.aspx.cs b/num-converter/WebForm1.aspx.cs index 07e672f..b11b88c 100644 --- a/num-converter/WebForm1.aspx.cs +++ b/num-converter/WebForm1.aspx.cs @@ -21,6 +21,7 @@ namespace num_converter int DecimalNum; int BinaryNum; int OctalNum; + string hexVal = string.Empty; int Base1 = 1; //dec to binary if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 2) @@ -46,14 +47,15 @@ namespace num_converter DecimalNum /= 8; } - lblResult.Text = "Oo" + Result; + lblResult.Text = Result; } //dec to hex if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 4) { - DecimalNum = Convert.ToInt32(txtInput.Text); - while (DecimalNum > 0) + DecimalNum = Convert.ToInt32(txtInput.Text); + hexVal = DecimalNum.ToString("X"); + /*while (DecimalNum > 0) { Remainder = DecimalNum % 16; string hexDigit = (Remainder < 10) @@ -61,9 +63,9 @@ namespace num_converter : ((char)('A' + Remainder - 10)).ToString(); Result = hexDigit + Result; DecimalNum /= 16; - } - - lblResult.Text = "0x" + Result; + }*/ + Result = hexVal; + lblResult.Text = Result; } //bin to dec if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1) @@ -85,7 +87,7 @@ namespace num_converter Result = Remainder.ToString() + Result; } - lblResult.Text = "Oo" + Result; + lblResult.Text = Result; } //bin to hex if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 4) @@ -113,6 +115,61 @@ namespace num_converter lblResult.Text = "0x" + Result;*/ } + + //octal to decimal + if (ddlSourcePosNum.SelectedIndex == 3 && ddlTargetPosNum.SelectedIndex == 1) + { + OctalNum = Convert.ToInt32(txtInput.Text, 8); + Result = Convert.ToString(OctalNum); + lblResult.Text = Result; + } + + if (ddlSourcePosNum.SelectedIndex == 3 && ddlTargetPosNum.SelectedIndex == 2) + { + DecimalNum = Convert.ToInt32(txtInput.Text, 8); + + while (DecimalNum > 0) + { + Remainder = DecimalNum % 2; + DecimalNum /= 2; + Result = Remainder.ToString() + Result; + } + lblResult.Text = Result; + } + + if (ddlSourcePosNum.SelectedIndex == 3 && ddlTargetPosNum.SelectedIndex == 4) + { + DecimalNum = Convert.ToInt32(txtInput.Text, 8); + hexVal = DecimalNum.ToString("X"); + Result = hexVal; + lblResult.Text = Result; + } + + if (ddlSourcePosNum.SelectedIndex == 4 && ddlTargetPosNum.SelectedIndex == 1) + { + hexVal = txtInput.Text; + DecimalNum = Convert.ToInt32(hexVal, 16); + Result = Convert.ToString(DecimalNum); + lblResult.Text = Result; + } + + if (ddlSourcePosNum.SelectedIndex == 4 && ddlTargetPosNum.SelectedIndex == 2) + { + hexVal = txtInput.Text; + DecimalNum = Convert.ToInt32(hexVal, 16); + Result = Convert.ToString(DecimalNum, 2); + lblResult.Text = Result; + } + + if (ddlSourcePosNum.SelectedIndex == 4 && ddlTargetPosNum.SelectedIndex == 3) + { + hexVal = txtInput.Text; + DecimalNum = Convert.ToInt32(hexVal, 16); + Result = Convert.ToString(DecimalNum, 8); + lblResult.Text = Result; + } + + } protected void btnClear_Click(object sender, EventArgs e)