Po kiego tak sobie życie komplikować? Jak już masz więcej niż dwa przeliczenia to zrób to sobie uniwersalnie:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SysConv
{
public partial class SysConv:Form
{
public SysConv()
{
InitializeComponent();
}
private void InpBox_TextChanged(object sender,EventArgs e)
{
StringBuilder r=new StringBuilder();
String s=InpBox.Text,dig="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int f=(int)InpSys.Value,t=(int)OutSys.Value;
for(int i=0;i<s.Length;++i)
{
int p=dig.IndexOf(char.ToUpper(s[i]));
if ((p < 0) || (p >= f))
{
OutBox.Text = "Error";
return;
}
for(int k=r.Length-1;k>=0;--k)
{
p+=dig.IndexOf(r[k])*f;
int n=p/t;
r[k]=dig[p-n*t];
p=n;
}
while(p>0)
{
int n=p/t;
r.Insert(0,dig[p-n*t]);
p=n;
}
}
OutBox.Text=r.ToString();
}
}
}
namespace SysConv
{
partial class SysConv
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components=null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing&&(components!=null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.InpBox = new System.Windows.Forms.TextBox();
this.InpSys = new System.Windows.Forms.NumericUpDown();
this.OutSys = new System.Windows.Forms.NumericUpDown();
this.OutBox = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.InpSys)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.OutSys)).BeginInit();
this.SuspendLayout();
//
// InpBox
//
this.InpBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.InpBox.Location = new System.Drawing.Point(12, 12);
this.InpBox.Name = "InpBox";
this.InpBox.Size = new System.Drawing.Size(790, 20);
this.InpBox.TabIndex = 0;
this.InpBox.Text = "255";
this.InpBox.TextChanged += new System.EventHandler(this.InpBox_TextChanged);
//
// InpSys
//
this.InpSys.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.InpSys.Location = new System.Drawing.Point(813, 12);
this.InpSys.Maximum = new decimal(new int[] {
36,
0,
0,
0});
this.InpSys.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.InpSys.Name = "InpSys";
this.InpSys.Size = new System.Drawing.Size(43, 20);
this.InpSys.TabIndex = 1;
this.InpSys.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.InpSys.Value = new decimal(new int[] {
10,
0,
0,
0});
this.InpSys.ValueChanged += new System.EventHandler(this.InpBox_TextChanged);
//
// OutSys
//
this.OutSys.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.OutSys.Location = new System.Drawing.Point(813, 38);
this.OutSys.Maximum = new decimal(new int[] {
36,
0,
0,
0});
this.OutSys.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.OutSys.Name = "OutSys";
this.OutSys.Size = new System.Drawing.Size(43, 20);
this.OutSys.TabIndex = 3;
this.OutSys.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.OutSys.Value = new decimal(new int[] {
2,
0,
0,
0});
this.OutSys.ValueChanged += new System.EventHandler(this.InpBox_TextChanged);
//
// OutBox
//
this.OutBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.OutBox.Location = new System.Drawing.Point(12, 38);
this.OutBox.Name = "OutBox";
this.OutBox.ReadOnly = true;
this.OutBox.Size = new System.Drawing.Size(790, 20);
this.OutBox.TabIndex = 2;
//
// SysConv
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(868, 70);
this.Controls.Add(this.OutSys);
this.Controls.Add(this.OutBox);
this.Controls.Add(this.InpSys);
this.Controls.Add(this.InpBox);
this.Name = "SysConv";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.InpSys)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.OutSys)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox InpBox;
private System.Windows.Forms.NumericUpDown InpSys;
private System.Windows.Forms.NumericUpDown OutSys;
private System.Windows.Forms.TextBox OutBox;
}
}