Browse Source

"finished" binary

test
lLewdie 1 year ago
parent
commit
f28dd6d5ea
  1. 51
      num-converter/WebForm1.aspx.cs

51
num-converter/WebForm1.aspx.cs

@ -22,7 +22,7 @@ namespace num_converter
int BinaryNum;
int OctalNum;
int Base1 = 1;
//dec to binary
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 2)
{
DecimalNum = Convert.ToInt32(txtInput.Text);
@ -34,7 +34,7 @@ namespace num_converter
}
lblResult.Text = Result;
}
//dec to oct
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 3)
{
@ -46,10 +46,10 @@ namespace num_converter
DecimalNum /= 8;
}
lblResult.Text = "0x" + Result;
lblResult.Text = "Oo" + Result;
}
//dec to hex
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 4)
{
DecimalNum = Convert.ToInt32(txtInput.Text);
@ -63,8 +63,9 @@ namespace num_converter
DecimalNum /= 16;
}
lblResult.Text = Result;
lblResult.Text = "0x" + Result;
}
//bin to dec
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1)
{
BinaryNum = Convert.ToInt32(txtInput.Text, 2);
@ -72,6 +73,46 @@ namespace num_converter
lblResult.Text = Result;
}
//binary to dec to oct
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 3)
{
BinaryNum = Convert.ToInt32(txtInput.Text, 2);
DecimalNum = BinaryNum;
while (DecimalNum > 0)
{
Remainder = DecimalNum % 2;
DecimalNum /= 2;
Result = Remainder.ToString() + Result;
}
lblResult.Text = "Oo" + Result;
}
//bin to hex
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 4)
{
string binaryNum = Convert.ToInt32(txtInput.Text, 2).ToString("X");
Result = binaryNum;
lblResult.Text = Result;
/*int binRemain = binaryNum.Length % 4;
if (binRemain != 0)
{
binaryNum = new string('O', 4 - binRemain) + binaryNum;
}
for (int i = 0; i < binaryNum.Length; i += 4)
{
string binaryGroup = binaryNum.Substring(i, 4);
DecimalNum = Convert.ToInt32(binaryGroup, 2);
string hexDigit = DecimalNum.ToString("X");
Result += hexDigit;
}
lblResult.Text = Result;
/* Result = BinaryNum.ToString();
lblResult.Text = "0x" + Result;*/
}
}
protected void btnClear_Click(object sender, EventArgs e)

Loading…
Cancel
Save