|
|
|
@ -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;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|