|
@ -21,6 +21,7 @@ namespace num_converter |
|
|
int DecimalNum; |
|
|
int DecimalNum; |
|
|
int BinaryNum; |
|
|
int BinaryNum; |
|
|
int OctalNum; |
|
|
int OctalNum; |
|
|
|
|
|
string hexVal = string.Empty; |
|
|
int Base1 = 1; |
|
|
int Base1 = 1; |
|
|
//dec to binary
|
|
|
//dec to binary
|
|
|
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 2) |
|
|
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 2) |
|
@ -46,14 +47,15 @@ namespace num_converter |
|
|
DecimalNum /= 8; |
|
|
DecimalNum /= 8; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
lblResult.Text = "Oo" + Result; |
|
|
lblResult.Text = Result; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
//dec to hex
|
|
|
//dec to hex
|
|
|
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 4) |
|
|
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 4) |
|
|
{ |
|
|
{ |
|
|
DecimalNum = Convert.ToInt32(txtInput.Text); |
|
|
DecimalNum = Convert.ToInt32(txtInput.Text); |
|
|
while (DecimalNum > 0) |
|
|
hexVal = DecimalNum.ToString("X"); |
|
|
|
|
|
/*while (DecimalNum > 0) |
|
|
{ |
|
|
{ |
|
|
Remainder = DecimalNum % 16; |
|
|
Remainder = DecimalNum % 16; |
|
|
string hexDigit = (Remainder < 10) |
|
|
string hexDigit = (Remainder < 10) |
|
@ -61,9 +63,9 @@ namespace num_converter |
|
|
: ((char)('A' + Remainder - 10)).ToString(); |
|
|
: ((char)('A' + Remainder - 10)).ToString(); |
|
|
Result = hexDigit + Result; |
|
|
Result = hexDigit + Result; |
|
|
DecimalNum /= 16; |
|
|
DecimalNum /= 16; |
|
|
} |
|
|
}*/ |
|
|
|
|
|
Result = hexVal; |
|
|
lblResult.Text = "0x" + Result; |
|
|
lblResult.Text = Result; |
|
|
} |
|
|
} |
|
|
//bin to dec
|
|
|
//bin to dec
|
|
|
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1) |
|
|
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1) |
|
@ -85,7 +87,7 @@ namespace num_converter |
|
|
Result = Remainder.ToString() + Result; |
|
|
Result = Remainder.ToString() + Result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
lblResult.Text = "Oo" + Result; |
|
|
lblResult.Text = Result; |
|
|
} |
|
|
} |
|
|
//bin to hex
|
|
|
//bin to hex
|
|
|
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 4) |
|
|
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 4) |
|
@ -113,6 +115,61 @@ namespace num_converter |
|
|
lblResult.Text = "0x" + Result;*/ |
|
|
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) |
|
|
protected void btnClear_Click(object sender, EventArgs e) |
|
|