using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; using libWin32.Win32.NumericConversion.IEEE754; namespace RomCheater.Docking { public partial class FloatingDataTypeConverter : DockContent { public FloatingDataTypeConverter() { InitializeComponent(); chkhexadecimal.Checked = true; } private void chkBinary_CheckedChanged(object sender, EventArgs e) { // binary input txtInput.InputType = NumericInputTypes.Binary; txtInput.Value = (0).ToString(); } private void chkdecimal_CheckedChanged(object sender, EventArgs e) { // decimal input txtInput.InputType = NumericInputTypes.Decimal; txtInput.Value = (0).ToString(); } private void chkhexadecimal_CheckedChanged(object sender, EventArgs e) { // hex input txtInput.InputType = NumericInputTypes.Hex; txtInput.Value = (0).ToString(); } private void chkoctal_CheckedChanged(object sender, EventArgs e) { // octal input txtInput.InputType = NumericInputTypes.Octal; txtInput.Value = (0).ToString(); } private void chkieee754float_CheckedChanged(object sender, EventArgs e) { //// 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); FloatConverter.SetFloatValue(Convert.ToSingle(txtDecimal.Value)); FloatConverter.CalculateHexFloat(); break; case NumericInputTypes.Hex: txtHex.Value = txtInput.Value; ConvertData(txtHex.Value, 16); FloatConverter.SetFloatHexValue(Convert.ToUInt32(txtHex.Value,16)); FloatConverter.CalculateFloat(); 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); //} } } }