Browse Source

Decimal done

test
lLewdie 1 year ago
parent
commit
ff79a11e56
  1. 36
      num-converter/WebForm1.aspx
  2. 31
      num-converter/WebForm1.aspx.cs
  3. 9
      num-converter/WebForm1.aspx.designer.cs

36
num-converter/WebForm1.aspx

@ -9,6 +9,16 @@
.auto-style1 { .auto-style1 {
width: 100%; width: 100%;
} }
.auto-style2 {
height: 30px;
}
.auto-style3 {
width: 284px;
}
.auto-style4 {
height: 30px;
width: 284px;
}
</style> </style>
</head> </head>
<body> <body>
@ -27,19 +37,20 @@
</div> </div>
<table align="center" class="auto-style1"> <table align="center" class="auto-style1">
<tr> <tr>
<td class="auto-style3">
Source Positional System</td>
<td> <td>
Target Positional System</td>
</tr>
<tr>
<td class="auto-style4">
<asp:DropDownList ID="ddlSourcePosNum" runat="server"> <asp:DropDownList ID="ddlSourcePosNum" runat="server">
<asp:ListItem Value="0">Select An Option</asp:ListItem> <asp:ListItem Value="0">Select An Option</asp:ListItem>
<asp:ListItem Value="1">Decimal</asp:ListItem> <asp:ListItem Value="1">Decimal</asp:ListItem>
<asp:ListItem Value="2">Binary</asp:ListItem> <asp:ListItem Value="2">Binary</asp:ListItem>
<asp:ListItem Value="3">Octal</asp:ListItem>
<asp:ListItem Value="4">Hexadecimal</asp:ListItem>
</asp:DropDownList> </asp:DropDownList>
</td> </td>
<td> <td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Convert to"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlTargetPosNum" runat="server"> <asp:DropDownList ID="ddlTargetPosNum" runat="server">
<asp:ListItem Value="0">Select An Option</asp:ListItem> <asp:ListItem Value="0">Select An Option</asp:ListItem>
<asp:ListItem Value="1">Decimal</asp:ListItem> <asp:ListItem Value="1">Decimal</asp:ListItem>
@ -50,28 +61,21 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td class="auto-style4">
<asp:TextBox ID="txtInput" runat="server"></asp:TextBox> <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
</td> </td>
<td>&nbsp;</td> <td class="auto-style2">
<td>
<asp:Label ID="lblResult" runat="server" BorderStyle="Double"></asp:Label> <asp:Label ID="lblResult" runat="server" BorderStyle="Double"></asp:Label>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td class="auto-style3">
<asp:Button ID="btnConvert" runat="server" OnClick="btnConvert_Click" Text="Convert" /> <asp:Button ID="btnConvert" runat="server" OnClick="btnConvert_Click" Text="Convert" />
</td> </td>
<td>&nbsp;</td>
<td> <td>
<asp:Button ID="btnClear" runat="server" OnClick="btnClear_Click" Text="Clear" /> <asp:Button ID="btnClear" runat="server" OnClick="btnClear_Click" Text="Clear" />
</td> </td>
</tr> </tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table> </table>
</form> </form>
</body> </body>

31
num-converter/WebForm1.aspx.cs

@ -34,6 +34,37 @@ namespace num_converter
} }
lblResult.Text = Result; lblResult.Text = Result;
} }
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 3)
{
DecimalNum = Convert.ToInt32(txtInput.Text);
while (DecimalNum > 0)
{
Remainder = DecimalNum % 8;
Result = Remainder.ToString() + Result;
DecimalNum /= 8;
}
lblResult.Text = "0x" + Result;
}
if (ddlSourcePosNum.SelectedIndex == 1 && ddlTargetPosNum.SelectedIndex == 4)
{
DecimalNum = Convert.ToInt32(txtInput.Text);
while (DecimalNum > 0)
{
Remainder = DecimalNum % 16;
string hexDigit = (Remainder < 10)
? Remainder.ToString()
: ((char)('A' + Remainder - 10)).ToString();
Result = hexDigit + Result;
DecimalNum /= 16;
}
lblResult.Text = Result;
}
if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1) if (ddlSourcePosNum.SelectedIndex == 2 && ddlTargetPosNum.SelectedIndex == 1)
{ {
BinaryNum = Convert.ToInt32(txtInput.Text, 2); BinaryNum = Convert.ToInt32(txtInput.Text, 2);

9
num-converter/WebForm1.aspx.designer.cs

@ -32,15 +32,6 @@ namespace num_converter
/// </remarks> /// </remarks>
protected global::System.Web.UI.WebControls.DropDownList ddlSourcePosNum; protected global::System.Web.UI.WebControls.DropDownList ddlSourcePosNum;
/// <summary>
/// Label1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label1;
/// <summary> /// <summary>
/// ddlTargetPosNum control. /// ddlTargetPosNum control.
/// </summary> /// </summary>

Loading…
Cancel
Save