/// <summary> /// Returns the binary representation of the octal number. /// </summary> public Binary GetBinary() { string binary = ""; for (int i = 0; i < octal.Length; i++) { NSConvert.Decimal @decimal = new Decimal(octal[i] - '0'); binary += @decimal.GetBinary(); } return(new Binary(binary)); }
private void decimalBtn_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(decimalTxt.Text) || string.IsNullOrWhiteSpace(decimalTxt.Text)) { MessageBox.Show("Enter decimal number to convert.", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error); reset(); return; } NSConvert.Decimal @decimal = new Decimal(double.Parse(decimalTxt.Text)); binaryTxt.Text = @decimal.GetBinary().ToString(); octalTxt.Text = @decimal.GetOctal().ToString(); hexadecimalTxt.Text = @decimal.GetHexadecimal().ToString(); } catch { MessageBox.Show("Invalid decimal format", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error); reset(); } }