Added spacing and padding support. (Note of known bug: For some reason, using the spacing combined with the auto compute feature causes an infinite loop, causing the program to crash.
This commit is contained in:
parent
7694424069
commit
1a788a3d9c
113
BaseConverter/Form1.Designer.cs
generated
113
BaseConverter/Form1.Designer.cs
generated
@ -65,11 +65,21 @@ namespace WindowsFormsApplication1
|
||||
this.octalTextBox = new System.Windows.Forms.TextBox();
|
||||
this.autoCompute = new System.Windows.Forms.CheckBox();
|
||||
this.autoComputeToolTip = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.paddingToggle = new System.Windows.Forms.CheckBox();
|
||||
this.groupBox5 = new System.Windows.Forms.GroupBox();
|
||||
this.paddingOffsetTextBox = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.groupBox6 = new System.Windows.Forms.GroupBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.spacingOffsetTextBox = new System.Windows.Forms.TextBox();
|
||||
this.spacingToggle = new System.Windows.Forms.CheckBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.binaryGroupBox.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.groupBox3.SuspendLayout();
|
||||
this.groupBox4.SuspendLayout();
|
||||
this.groupBox5.SuspendLayout();
|
||||
this.groupBox6.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// computeButton
|
||||
@ -256,13 +266,100 @@ namespace WindowsFormsApplication1
|
||||
// autoComputeToolTip
|
||||
//
|
||||
this.autoComputeToolTip.IsBalloon = true;
|
||||
//this.autoComputeToolTip.Popup += new System.Windows.Forms.PopupEventHandler(this.autoComputeToolTip_Popup);
|
||||
//
|
||||
// paddingToggle
|
||||
//
|
||||
this.paddingToggle.AutoSize = true;
|
||||
this.paddingToggle.Location = new System.Drawing.Point(6, 19);
|
||||
this.paddingToggle.Name = "paddingToggle";
|
||||
this.paddingToggle.Size = new System.Drawing.Size(81, 17);
|
||||
this.paddingToggle.TabIndex = 9;
|
||||
this.paddingToggle.Text = "Pad Zeros?";
|
||||
this.paddingToggle.UseVisualStyleBackColor = true;
|
||||
this.paddingToggle.CheckedChanged += new System.EventHandler(this.paddingToggle_CheckedChanged);
|
||||
//
|
||||
// groupBox5
|
||||
//
|
||||
this.groupBox5.Controls.Add(this.label1);
|
||||
this.groupBox5.Controls.Add(this.paddingOffsetTextBox);
|
||||
this.groupBox5.Controls.Add(this.paddingToggle);
|
||||
this.groupBox5.Location = new System.Drawing.Point(295, 13);
|
||||
this.groupBox5.Name = "groupBox5";
|
||||
this.groupBox5.Size = new System.Drawing.Size(89, 88);
|
||||
this.groupBox5.TabIndex = 10;
|
||||
this.groupBox5.TabStop = false;
|
||||
this.groupBox5.Text = "Padding";
|
||||
//
|
||||
// paddingOffsetTextBox
|
||||
//
|
||||
this.paddingOffsetTextBox.Location = new System.Drawing.Point(7, 59);
|
||||
this.paddingOffsetTextBox.Name = "paddingOffsetTextBox";
|
||||
this.paddingOffsetTextBox.ReadOnly = true;
|
||||
this.paddingOffsetTextBox.Size = new System.Drawing.Size(76, 20);
|
||||
this.paddingOffsetTextBox.TabIndex = 10;
|
||||
this.paddingOffsetTextBox.Text = "8";
|
||||
this.paddingOffsetTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Location = new System.Drawing.Point(7, 39);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(76, 14);
|
||||
this.label1.TabIndex = 11;
|
||||
this.label1.Text = "Padding offset";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// groupBox6
|
||||
//
|
||||
this.groupBox6.Controls.Add(this.label2);
|
||||
this.groupBox6.Controls.Add(this.spacingOffsetTextBox);
|
||||
this.groupBox6.Controls.Add(this.spacingToggle);
|
||||
this.groupBox6.Location = new System.Drawing.Point(295, 107);
|
||||
this.groupBox6.Name = "groupBox6";
|
||||
this.groupBox6.Size = new System.Drawing.Size(89, 88);
|
||||
this.groupBox6.TabIndex = 12;
|
||||
this.groupBox6.TabStop = false;
|
||||
this.groupBox6.Text = "Spacing";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label2.Location = new System.Drawing.Point(7, 39);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(76, 14);
|
||||
this.label2.TabIndex = 11;
|
||||
this.label2.Text = "Spacing Offset";
|
||||
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// spacingOffsetTextBox
|
||||
//
|
||||
this.spacingOffsetTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.spacingOffsetTextBox.Location = new System.Drawing.Point(7, 59);
|
||||
this.spacingOffsetTextBox.Name = "spacingOffsetTextBox";
|
||||
this.spacingOffsetTextBox.ReadOnly = true;
|
||||
this.spacingOffsetTextBox.Size = new System.Drawing.Size(76, 20);
|
||||
this.spacingOffsetTextBox.TabIndex = 10;
|
||||
this.spacingOffsetTextBox.Text = "4";
|
||||
this.spacingOffsetTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
||||
//
|
||||
// spacingToggle
|
||||
//
|
||||
this.spacingToggle.AutoSize = true;
|
||||
this.spacingToggle.Location = new System.Drawing.Point(6, 19);
|
||||
this.spacingToggle.Name = "spacingToggle";
|
||||
this.spacingToggle.Size = new System.Drawing.Size(71, 17);
|
||||
this.spacingToggle.TabIndex = 9;
|
||||
this.spacingToggle.Text = "Spacing?";
|
||||
this.spacingToggle.UseVisualStyleBackColor = true;
|
||||
this.spacingToggle.CheckedChanged += new System.EventHandler(this.spacingToggle_CheckedChanged);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(300, 364);
|
||||
this.ClientSize = new System.Drawing.Size(396, 364);
|
||||
this.Controls.Add(this.groupBox6);
|
||||
this.Controls.Add(this.groupBox5);
|
||||
this.Controls.Add(this.autoCompute);
|
||||
this.Controls.Add(this.groupBox4);
|
||||
this.Controls.Add(this.groupBox3);
|
||||
@ -284,6 +381,10 @@ namespace WindowsFormsApplication1
|
||||
this.groupBox3.PerformLayout();
|
||||
this.groupBox4.ResumeLayout(false);
|
||||
this.groupBox4.PerformLayout();
|
||||
this.groupBox5.ResumeLayout(false);
|
||||
this.groupBox5.PerformLayout();
|
||||
this.groupBox6.ResumeLayout(false);
|
||||
this.groupBox6.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -309,6 +410,14 @@ namespace WindowsFormsApplication1
|
||||
private System.Windows.Forms.TextBox octalTextBox;
|
||||
private System.Windows.Forms.CheckBox autoCompute;
|
||||
private System.Windows.Forms.ToolTip autoComputeToolTip;
|
||||
private System.Windows.Forms.CheckBox paddingToggle;
|
||||
private System.Windows.Forms.GroupBox groupBox5;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.TextBox paddingOffsetTextBox;
|
||||
private System.Windows.Forms.GroupBox groupBox6;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.TextBox spacingOffsetTextBox;
|
||||
private System.Windows.Forms.CheckBox spacingToggle;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,21 @@ namespace WindowsFormsApplication1
|
||||
{
|
||||
// Define variables
|
||||
long decimalNum = 0, hexNum = 0, binNum = 0, octalNum = 0;
|
||||
int paddingOffset = 0,spacingOffset = 0, i = 0;
|
||||
|
||||
try
|
||||
{ // Extract data from text boxes.
|
||||
decimalNum = long.Parse(decimalTextBox.Text);
|
||||
hexNum = Convert.ToInt64(hexTextBox.Text, 16);
|
||||
// Remove spacing from binaryTextBox before parsing it
|
||||
if (spacingToggle.Checked)
|
||||
{
|
||||
binaryTextBox.Text = binaryTextBox.Text.Replace(" ", "");
|
||||
}
|
||||
binNum = Convert.ToInt64(binaryTextBox.Text, 2);
|
||||
octalNum = Convert.ToInt64(octalTextBox.Text, 8);
|
||||
paddingOffset = int.Parse(paddingOffsetTextBox.Text);
|
||||
spacingOffset = int.Parse(spacingOffsetTextBox.Text);
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
@ -94,12 +102,54 @@ namespace WindowsFormsApplication1
|
||||
currentFocus("binaryTextBox");
|
||||
}
|
||||
// Print output
|
||||
decimalTextBox.Text = decimalNum.ToString();
|
||||
if (paddingToggle.Checked) // Padding: Add Zeros to the beginning of the string
|
||||
{
|
||||
string binaryString = Convert.ToString(binNum, 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))
|
||||
{
|
||||
binaryString = "0" + binaryString;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
binaryTextBox.Text = binaryString;
|
||||
}
|
||||
else
|
||||
{
|
||||
binaryTextBox.Text = Convert.ToString(binNum, 2);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (spacingToggle.Checked)
|
||||
{
|
||||
string binaryString = binaryTextBox.Text; // Define string to offset
|
||||
int binarySize = binaryString.Length; //count the length of the string.
|
||||
i = binarySize;
|
||||
var builder = new StringBuilder(binaryString); // String builder
|
||||
while (i != 0)
|
||||
{
|
||||
if (i % spacingOffset == 0) // If i mod spacingOffset equals zero, append a space to the offset specified by i.
|
||||
{
|
||||
builder.Insert(i, " ");
|
||||
}
|
||||
i--;
|
||||
}
|
||||
binaryTextBox.Text = builder.ToString();
|
||||
builder = null; // null out builder when done
|
||||
//binaryTextBox.Text = binaryString;
|
||||
}
|
||||
} catch (Exception Ex) {
|
||||
MessageBox.Show("Divide by zero");
|
||||
}
|
||||
hexTextBox.Text = hexNum.ToString("X");
|
||||
binaryTextBox.Text = Convert.ToString(binNum, 2);
|
||||
octalTextBox.Text = Convert.ToString(octalNum, 8);
|
||||
decimalTextBox.Text = decimalNum.ToString();
|
||||
}
|
||||
private void currentFocus(string focusOn) {
|
||||
private void currentFocus(string focusOn)
|
||||
{
|
||||
switch (focusOn)
|
||||
{
|
||||
case "binaryTextBox":
|
||||
@ -197,5 +247,29 @@ namespace WindowsFormsApplication1
|
||||
if (autoCompute.Checked)
|
||||
compute();
|
||||
}
|
||||
|
||||
private void paddingToggle_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (paddingToggle.Checked)
|
||||
{
|
||||
paddingOffsetTextBox.ReadOnly = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
paddingOffsetTextBox.ReadOnly = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void spacingToggle_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (spacingToggle.Checked)
|
||||
{
|
||||
spacingOffsetTextBox.ReadOnly = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
spacingOffsetTextBox.ReadOnly = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>yuucww+k7TDTPDj046KVMAquP4M=</dsig:DigestValue>
|
||||
<dsig:DigestValue>M1+IlQiQJ4OfFXw+8V52dd47UwQ=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -52,14 +52,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="13824">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="16896">
|
||||
<assemblyIdentity name="BaseConverter" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>AZ1RyIR6zUElaFiQPabdRc1KQGU=</dsig:DigestValue>
|
||||
<dsig:DigestValue>UiwtToWaxlHHmAc6iXW07oBqZio=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -11,7 +11,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>yuucww+k7TDTPDj046KVMAquP4M=</dsig:DigestValue>
|
||||
<dsig:DigestValue>M1+IlQiQJ4OfFXw+8V52dd47UwQ=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
@ -11,7 +11,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>ZheybUAJpg39YCWBJx+Gc4mkZw4=</dsig:DigestValue>
|
||||
<dsig:DigestValue>o9qGPInDcM+MIPFuzS1NJwC3Lk8=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -52,14 +52,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="13312">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="16384">
|
||||
<assemblyIdentity name="BaseConverter" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>GXF67NBKCPtbhPkDo1mD8A/wVqU=</dsig:DigestValue>
|
||||
<dsig:DigestValue>DHImL6Kx0jD1DC/eCcyyWDlW0JI=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -11,7 +11,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>yuucww+k7TDTPDj046KVMAquP4M=</dsig:DigestValue>
|
||||
<dsig:DigestValue>M1+IlQiQJ4OfFXw+8V52dd47UwQ=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -52,14 +52,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="13824">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="16896">
|
||||
<assemblyIdentity name="BaseConverter" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>AZ1RyIR6zUElaFiQPabdRc1KQGU=</dsig:DigestValue>
|
||||
<dsig:DigestValue>UiwtToWaxlHHmAc6iXW07oBqZio=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
@ -11,7 +11,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>ZheybUAJpg39YCWBJx+Gc4mkZw4=</dsig:DigestValue>
|
||||
<dsig:DigestValue>o9qGPInDcM+MIPFuzS1NJwC3Lk8=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -52,14 +52,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="13312">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="BaseConverter.exe" size="16384">
|
||||
<assemblyIdentity name="BaseConverter" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||
<dsig:DigestValue>GXF67NBKCPtbhPkDo1mD8A/wVqU=</dsig:DigestValue>
|
||||
<dsig:DigestValue>DHImL6Kx0jD1DC/eCcyyWDlW0JI=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user