Refactor. Turn padding and spacing into their own functions.
This commit is contained in:
parent
0e7dff04e5
commit
321023cd33
BIN
.vs/BaseConverter/FileContentIndex/08a30b27-fdaa-44cd-a234-8f9a12a28392.vsidx
Executable file
BIN
.vs/BaseConverter/FileContentIndex/08a30b27-fdaa-44cd-a234-8f9a12a28392.vsidx
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.vs/BaseConverter/FileContentIndex/504d2f8f-ab3e-4738-831b-54075af77482.vsidx
Executable file
BIN
.vs/BaseConverter/FileContentIndex/504d2f8f-ab3e-4738-831b-54075af77482.vsidx
Executable file
Binary file not shown.
BIN
.vs/BaseConverter/FileContentIndex/55336870-9bdd-4740-9ec8-4b9e1379ab00.vsidx
Executable file
BIN
.vs/BaseConverter/FileContentIndex/55336870-9bdd-4740-9ec8-4b9e1379ab00.vsidx
Executable file
Binary file not shown.
Binary file not shown.
14
BaseConverter/Form1.Designer.cs
generated
14
BaseConverter/Form1.Designer.cs
generated
@ -121,7 +121,7 @@ namespace WindowsFormsApplication1
|
||||
this.hexTextBox.Size = new System.Drawing.Size(261, 20);
|
||||
this.hexTextBox.TabIndex = 0;
|
||||
this.hexTextBox.Text = "0";
|
||||
this.hexTextBox.TextChanged += new System.EventHandler(this.hexTextBox_TextChanged);
|
||||
this.hexTextBox.Click += new System.EventHandler(this.hexTextBox_Enter);
|
||||
//
|
||||
// binaryGroupBox
|
||||
//
|
||||
@ -141,7 +141,7 @@ namespace WindowsFormsApplication1
|
||||
this.binaryTextBox.Size = new System.Drawing.Size(261, 20);
|
||||
this.binaryTextBox.TabIndex = 0;
|
||||
this.binaryTextBox.Text = "0";
|
||||
this.binaryTextBox.TextChanged += new System.EventHandler(this.binaryTextBox_TextChanged);
|
||||
this.binaryTextBox.Click += new System.EventHandler(this.binaryTextBox_Enter);
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
@ -161,7 +161,7 @@ namespace WindowsFormsApplication1
|
||||
this.decimalTextBox.Size = new System.Drawing.Size(261, 20);
|
||||
this.decimalTextBox.TabIndex = 0;
|
||||
this.decimalTextBox.Text = "0";
|
||||
this.decimalTextBox.TextChanged += new System.EventHandler(this.decimalTextBox_TextChanged);
|
||||
this.decimalTextBox.Click += new System.EventHandler(this.decimalTextBox_Enter);
|
||||
//
|
||||
// exitButton
|
||||
//
|
||||
@ -252,16 +252,16 @@ namespace WindowsFormsApplication1
|
||||
this.octalTextBox.Size = new System.Drawing.Size(261, 20);
|
||||
this.octalTextBox.TabIndex = 0;
|
||||
this.octalTextBox.Text = "0";
|
||||
this.octalTextBox.TextChanged += new System.EventHandler(this.octalTextBox_TextChanged);
|
||||
this.octalTextBox.Click += new System.EventHandler(this.octalTextBox_Enter);
|
||||
//
|
||||
// autoCompute
|
||||
//
|
||||
this.autoCompute.AutoSize = true;
|
||||
this.autoCompute.Location = new System.Drawing.Point(16, 310);
|
||||
this.autoCompute.Name = "autoCompute";
|
||||
this.autoCompute.Size = new System.Drawing.Size(138, 17);
|
||||
this.autoCompute.Size = new System.Drawing.Size(170, 17);
|
||||
this.autoCompute.TabIndex = 8;
|
||||
this.autoCompute.Text = "Automatically compute?";
|
||||
this.autoCompute.Text = "Compute upon pressing enter?";
|
||||
this.autoCompute.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// autoComputeToolTip
|
||||
@ -358,7 +358,7 @@ namespace WindowsFormsApplication1
|
||||
// debugLabel
|
||||
//
|
||||
this.debugLabel.AutoSize = true;
|
||||
this.debugLabel.Location = new System.Drawing.Point(160, 311);
|
||||
this.debugLabel.Location = new System.Drawing.Point(192, 311);
|
||||
this.debugLabel.Name = "debugLabel";
|
||||
this.debugLabel.Size = new System.Drawing.Size(63, 13);
|
||||
this.debugLabel.TabIndex = 14;
|
||||
|
@ -39,7 +39,13 @@ namespace WindowsFormsApplication1
|
||||
|
||||
}
|
||||
int paddingOffset = 0, spacingOffset = 0, i = 0;
|
||||
public void compute()
|
||||
|
||||
public void printToBinary(string whatToPrint)
|
||||
{
|
||||
binaryTextBox.Text = whatToPrint;
|
||||
}
|
||||
|
||||
public long compute()
|
||||
{
|
||||
// Define variables
|
||||
long decimalNum = 0, hexNum = 0, binNum = 0, octalNum = 0;
|
||||
@ -103,49 +109,64 @@ namespace WindowsFormsApplication1
|
||||
currentFocus("binaryTextBox");
|
||||
}
|
||||
// Print output
|
||||
hexTextBox.Text = hexNum.ToString("X");
|
||||
octalTextBox.Text = Convert.ToString(octalNum, 8);
|
||||
decimalTextBox.Text = decimalNum.ToString();
|
||||
return binNum;
|
||||
}
|
||||
public string padding(long paddingInput)
|
||||
{
|
||||
if (paddingToggle.Checked) // Padding: Add Zeros to the beginning of the string
|
||||
{
|
||||
string binaryString = Convert.ToString(binNum, 2); // Define string to offset
|
||||
string binaryString = Convert.ToString(paddingInput, 2); // Define string to offset
|
||||
int binarySize = binaryString.Length; //count the length of the string.
|
||||
|
||||
if (paddingOffset > binarySize)
|
||||
{ // Is the decimal offset larger than the size of ths string?
|
||||
while (i != (paddingOffset - binarySize))
|
||||
while (i <= (paddingOffset - binarySize))
|
||||
{
|
||||
binaryString = "0" + binaryString;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
binaryTextBox.Text = binaryString;
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
return binaryString;
|
||||
}
|
||||
else
|
||||
{
|
||||
binaryTextBox.Text = Convert.ToString(binNum, 2);
|
||||
return Convert.ToString(paddingInput, 2);
|
||||
}
|
||||
|
||||
hexTextBox.Text = hexNum.ToString("X");
|
||||
octalTextBox.Text = Convert.ToString(octalNum, 8);
|
||||
decimalTextBox.Text = decimalNum.ToString();
|
||||
}
|
||||
public void spacing()
|
||||
public string spacing(string binaryString)
|
||||
{
|
||||
spacingOffset = int.Parse(spacingOffsetTextBox.Text);
|
||||
try
|
||||
{
|
||||
if (spacingToggle.Checked)
|
||||
{
|
||||
string binaryString = binaryTextBox.Text; // Define string to offset
|
||||
//string binaryString = spacingInput; // Define string to offset
|
||||
int binarySize = binaryString.Length; //count the length of the string.
|
||||
i = binarySize;
|
||||
i = binarySize; //- (spacingOffset + 1);
|
||||
int spacingCounterOffset = 0;
|
||||
var builder = new StringBuilder(binaryString); // String builder
|
||||
/*
|
||||
if (binarySize % 2 == 0) // compensate for numbers being odd
|
||||
{
|
||||
spacingCounterOffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
spacingCounterOffset = spacingOffset - 1;
|
||||
}
|
||||
*/
|
||||
while (i != 0)
|
||||
{
|
||||
if (!(i == binarySize)) // Get rid of trailing space
|
||||
{
|
||||
if (i % spacingOffset == 0) // If i mod spacingOffset equals zero, append a space to the offset specified by i.
|
||||
{
|
||||
builder.Insert(i, " ");
|
||||
builder.Insert((i - spacingCounterOffset), " ");
|
||||
//spacingCounterOffset++;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
@ -154,7 +175,7 @@ namespace WindowsFormsApplication1
|
||||
i--;
|
||||
}
|
||||
}
|
||||
binaryTextBox.Text = builder.ToString();
|
||||
return builder.ToString();
|
||||
//builder = null; // null out builder when done
|
||||
//binaryTextBox.Text = binaryString;
|
||||
}
|
||||
@ -163,6 +184,7 @@ namespace WindowsFormsApplication1
|
||||
{
|
||||
MessageBox.Show("Divide by zero");
|
||||
}
|
||||
return binaryString;
|
||||
}
|
||||
private void currentFocus(string focusOn)
|
||||
{
|
||||
@ -200,8 +222,10 @@ namespace WindowsFormsApplication1
|
||||
decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
compute();
|
||||
spacing();
|
||||
|
||||
// Set binary output
|
||||
string paddingString = padding(compute());
|
||||
binaryTextBox.Text = spacing(paddingString);
|
||||
}
|
||||
|
||||
private void clearButton_Click(object sender, EventArgs e)
|
||||
@ -245,52 +269,7 @@ namespace WindowsFormsApplication1
|
||||
currentFocus("octalTextBox");
|
||||
}
|
||||
|
||||
private void binaryTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
{
|
||||
// Remove commas from decimalTextBox before parsing it
|
||||
//decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
compute();
|
||||
//spacing();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void hexTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
{
|
||||
// Remove commas from decimalTextBox before parsing it
|
||||
decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
|
||||
compute();
|
||||
spacing();
|
||||
}
|
||||
}
|
||||
private void octalTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
{
|
||||
// Remove commas from decimalTextBox before parsing it
|
||||
decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
|
||||
compute();
|
||||
spacing();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void decimalTextBox_TextChanged(object sender, EventArgs e)
|
||||
private void binaryTextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
@ -300,9 +279,58 @@ namespace WindowsFormsApplication1
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
|
||||
compute();
|
||||
Thread.Sleep(250);
|
||||
spacing();
|
||||
// Set binary output
|
||||
string paddingString = padding(compute());
|
||||
binaryTextBox.Text = spacing(paddingString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void hexTextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
{
|
||||
// Remove commas from decimalTextBox before parsing it
|
||||
decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
|
||||
// Set binary output
|
||||
string paddingString = padding(compute());
|
||||
binaryTextBox.Text = spacing(paddingString);
|
||||
}
|
||||
}
|
||||
private void octalTextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
{
|
||||
// Remove commas from decimalTextBox before parsing it
|
||||
decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
|
||||
// Set binary output
|
||||
string paddingString = padding(compute());
|
||||
binaryTextBox.Text = spacing(paddingString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void decimalTextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
//debugLabel.Text = sender.GetType().ToString();
|
||||
if (autoCompute.Checked & (sender.GetType().ToString().Equals("System.Windows.Forms.TextBox")))
|
||||
{
|
||||
// Remove commas from decimalTextBox before parsing it
|
||||
//decimalTextBox.Text = decimalTextBox.Text.Replace(",", "");
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
|
||||
// Set binary output
|
||||
string paddingString = padding(compute());
|
||||
binaryTextBox.Text = spacing(paddingString);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,12 +112,12 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="autoComputeToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<metadata name="autoComputeToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>FLb7o5PmMolOEu475l0smDzDYPLdyAdRY/RzK0kEIiY=</dsig:DigestValue>
|
||||
<dsig:DigestValue>/rV8ETvxmwvaJgmA8G++8CRvC5PaSPtVNGW0eHdPwfI=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -49,7 +49,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>RykjKwuxJc8SDlNEdmViyEwnW/WDjfua+galOLDEBps=</dsig:DigestValue>
|
||||
<dsig:DigestValue>6QZaxI7Qf42UjLMkjvkpSc+vkOrsV7rHWYV3m96IzcM=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>FLb7o5PmMolOEu475l0smDzDYPLdyAdRY/RzK0kEIiY=</dsig:DigestValue>
|
||||
<dsig:DigestValue>/rV8ETvxmwvaJgmA8G++8CRvC5PaSPtVNGW0eHdPwfI=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -25,3 +25,18 @@ Z:\home\caleb\Base-Converter\BaseConverter\obj\Debug\BaseConverter.exe.manifest
|
||||
Z:\home\caleb\Base-Converter\BaseConverter\obj\Debug\BaseConverter.application
|
||||
Z:\home\caleb\Base-Converter\BaseConverter\obj\Debug\BaseConverter.exe
|
||||
Z:\home\caleb\Base-Converter\BaseConverter\obj\Debug\BaseConverter.pdb
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\bin\Debug\BaseConverter.exe.config
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\bin\Debug\BaseConverter.exe.manifest
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\bin\Debug\BaseConverter.application
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\bin\Debug\BaseConverter.exe
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\bin\Debug\BaseConverter.pdb
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.csproj.AssemblyReference.cache
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.csproj.SuggestedBindingRedirects.cache
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\WindowsFormsApplication1.Form1.resources
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.csproj.GenerateResource.cache
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.csproj.CoreCompileInputs.cache
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.exe.manifest
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.application
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.exe
|
||||
Z:\media\DataEXT4\Documents\Base-Converter\BaseConverter\obj\Debug\BaseConverter.pdb
|
||||
|
Binary file not shown.
Binary file not shown.
@ -49,7 +49,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>RykjKwuxJc8SDlNEdmViyEwnW/WDjfua+galOLDEBps=</dsig:DigestValue>
|
||||
<dsig:DigestValue>6QZaxI7Qf42UjLMkjvkpSc+vkOrsV7rHWYV3m96IzcM=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user