Parent Directory
|
Revision Log
|
Patch
--- trunk/RomCheater/Docking/FloatingDataTypeConverter.cs 2012/06/02 13:20:13 223 +++ trunk/RomCheater/Docking/FloatingDataTypeConverter.cs 2012/06/02 14:54:17 226 @@ -7,6 +7,7 @@ using System.Text; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; +using libWin32.Win32.NumericConversion.IEEE754; namespace RomCheater.Docking { @@ -21,31 +22,138 @@ private void chkBinary_CheckedChanged(object sender, EventArgs e) { // binary input - txtInput.InputType = MultiNumericBox_InputType.Binary; + txtInput.InputType = NumericInputTypes.Binary; + txtInput.Value = (0).ToString(); } private void chkdecimal_CheckedChanged(object sender, EventArgs e) { // decimal input - txtInput.InputType = MultiNumericBox_InputType.Decimal; + txtInput.InputType = NumericInputTypes.Decimal; + txtInput.Value = (0).ToString(); } private void chkhexadecimal_CheckedChanged(object sender, EventArgs e) { // hex input - txtInput.InputType = MultiNumericBox_InputType.Hex; + txtInput.InputType = NumericInputTypes.Hex; + txtInput.Value = (0).ToString(); } private void chkoctal_CheckedChanged(object sender, EventArgs e) { // octal input - txtInput.InputType = MultiNumericBox_InputType.Octal; + txtInput.InputType = NumericInputTypes.Octal; + txtInput.Value = (0).ToString(); } private void chkieee754float_CheckedChanged(object sender, EventArgs e) { - // IEEE754 Hex Float (hex) - txtInput.InputType = MultiNumericBox_InputType.IEEE754HexFloat; + //// IEEE754 Hex Float (hex) + //txtInput.InputType = NumericInputTypes.IEEE754HexFloat; + //txtInput.Value = (0).ToString(); + } + + private void btnConvert_Click(object sender, EventArgs e) + { + try + { + switch (txtInput.InputType) + { + case NumericInputTypes.Binary: + txtBinary.Value = txtInput.Value; + ConvertData(txtBinary.Value, 2); + break; + case NumericInputTypes.Decimal: + txtDecimal.Value = txtInput.Value; + ConvertData(txtDecimal.Value, 10); + break; + case NumericInputTypes.Hex: + txtHex.Value = txtInput.Value; + ConvertData(txtHex.Value, 16); + break; + //case NumericInputTypes.IEEE754HexFloat: + // txtFloat.Value = txtInput.Value; + // ConvertData(txtFloat.Value, 16); + // break; + case NumericInputTypes.Octal: + txtOctal.Value = (txtInput.Value.StartsWith("0")) ? txtInput.Value : string.Format("0{0}", txtInput.Value); + ConvertData(txtOctal.Value, 8); + break; + } + } + catch (FormatException ex) + { + MessageBox.Show(ex.ToString(),"Encountered an error in the input format", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (Exception ex) + { + MessageBox.Show(ex.ToString(),"Encountered an error while converting the data", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ConvertData(string value, int FromBase) + { + // binary + if (txtInput.InputType != NumericInputTypes.Binary) + { + int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + txtBinary.Value = Convert.ToString(val, 2); + //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) + //{ + // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); + // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + // converter.HexFloat = val2; + // txtBinary.Value = Convert.ToString(converter.Float); + //} + } + // decimal + if (txtInput.InputType != NumericInputTypes.Decimal) + { + int val = Convert.ToInt32(value, FromBase); + txtDecimal.Value = Convert.ToString(val, 10); + //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) + //{ + // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); + // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + // converter.HexFloat = val2; + // txtDecimal.Value = string.Format("{0:R}", converter.Float); + //} + } + // hex + if (txtInput.InputType != NumericInputTypes.Hex) + { + int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + txtHex.Value = Convert.ToString(val, 16); + //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) + //{ + // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); + // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + // converter.HexFloat = val2; + //} + } + // octal + if (txtInput.InputType != NumericInputTypes.Octal) + { + int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + txtOctal.Value = Convert.ToString(val, 8); + //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) + //{ + // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); + // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + // converter.HexFloat = val2; + //} + } + //// float + //if (txtInput.InputType != NumericInputTypes.IEEE754HexFloat) + //{ + // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); + // uint val = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase); + // float f = Convert.ToSingle(val); + // converter.Float = f; + // //txtFloat.Value = string.Format("{0:R}", converter.Float); + // txtFloat.Value = string.Format("0x{0:x8}", converter.HexFloat); + //} } } }
ViewVC Help | |
Powered by ViewVC 1.1.22 |