--- trunk/RomCheater/Docking/FloatingDataTypeConverter.cs 2012/06/02 14:29:00 225 +++ trunk/RomCheater/Docking/FloatingDataTypeConverter.cs 2012/06/02 14:54:17 226 @@ -49,35 +49,46 @@ namespace RomCheater.Docking private void chkieee754float_CheckedChanged(object sender, EventArgs e) { - // IEEE754 Hex Float (hex) - txtInput.InputType = NumericInputTypes.IEEE754HexFloat; - txtInput.Value = (0).ToString(); + //// IEEE754 Hex Float (hex) + //txtInput.InputType = NumericInputTypes.IEEE754HexFloat; + //txtInput.Value = (0).ToString(); } private void btnConvert_Click(object sender, EventArgs e) { - switch (txtInput.InputType) + try { - 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; + 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); } } @@ -86,63 +97,63 @@ namespace RomCheater.Docking // binary if (txtInput.InputType != NumericInputTypes.Binary) { - int val = Convert.ToInt32(value, FromBase); + 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, FromBase); - converter.HexFloat = val2; - txtBinary.Value = Convert.ToString(converter.Float); - } + //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, FromBase); - converter.HexFloat = val2; - txtDecimal.Value = string.Format("{0:R}", converter.Float); - } + //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, FromBase); + 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, FromBase); - converter.HexFloat = val2; - } + //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, FromBase); + 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, FromBase); - converter.HexFloat = val2; - } - } - // float - if (txtInput.InputType != NumericInputTypes.IEEE754HexFloat) - { - ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); - uint val = Convert.ToUInt32(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); - } + //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); + //} } } } |