/[RomCheater]/trunk/RomCheater/Docking/FloatingDataTypeConverter.cs
ViewVC logotype

Contents of /trunk/RomCheater/Docking/FloatingDataTypeConverter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (show annotations) (download)
Sat Jun 2 14:54:17 2012 UTC (8 years, 5 months ago) by william
File size: 7049 byte(s)
+ commit final wip for numeric datatype converter

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using WeifenLuo.WinFormsUI.Docking;
10 using libWin32.Win32.NumericConversion.IEEE754;
11
12 namespace RomCheater.Docking
13 {
14 public partial class FloatingDataTypeConverter : DockContent
15 {
16 public FloatingDataTypeConverter()
17 {
18 InitializeComponent();
19 chkhexadecimal.Checked = true;
20 }
21
22 private void chkBinary_CheckedChanged(object sender, EventArgs e)
23 {
24 // binary input
25 txtInput.InputType = NumericInputTypes.Binary;
26 txtInput.Value = (0).ToString();
27 }
28
29 private void chkdecimal_CheckedChanged(object sender, EventArgs e)
30 {
31 // decimal input
32 txtInput.InputType = NumericInputTypes.Decimal;
33 txtInput.Value = (0).ToString();
34 }
35
36 private void chkhexadecimal_CheckedChanged(object sender, EventArgs e)
37 {
38 // hex input
39 txtInput.InputType = NumericInputTypes.Hex;
40 txtInput.Value = (0).ToString();
41 }
42
43 private void chkoctal_CheckedChanged(object sender, EventArgs e)
44 {
45 // octal input
46 txtInput.InputType = NumericInputTypes.Octal;
47 txtInput.Value = (0).ToString();
48 }
49
50 private void chkieee754float_CheckedChanged(object sender, EventArgs e)
51 {
52 //// IEEE754 Hex Float (hex)
53 //txtInput.InputType = NumericInputTypes.IEEE754HexFloat;
54 //txtInput.Value = (0).ToString();
55 }
56
57 private void btnConvert_Click(object sender, EventArgs e)
58 {
59 try
60 {
61 switch (txtInput.InputType)
62 {
63 case NumericInputTypes.Binary:
64 txtBinary.Value = txtInput.Value;
65 ConvertData(txtBinary.Value, 2);
66 break;
67 case NumericInputTypes.Decimal:
68 txtDecimal.Value = txtInput.Value;
69 ConvertData(txtDecimal.Value, 10);
70 break;
71 case NumericInputTypes.Hex:
72 txtHex.Value = txtInput.Value;
73 ConvertData(txtHex.Value, 16);
74 break;
75 //case NumericInputTypes.IEEE754HexFloat:
76 // txtFloat.Value = txtInput.Value;
77 // ConvertData(txtFloat.Value, 16);
78 // break;
79 case NumericInputTypes.Octal:
80 txtOctal.Value = (txtInput.Value.StartsWith("0")) ? txtInput.Value : string.Format("0{0}", txtInput.Value);
81 ConvertData(txtOctal.Value, 8);
82 break;
83 }
84 }
85 catch (FormatException ex)
86 {
87 MessageBox.Show(ex.ToString(),"Encountered an error in the input format", MessageBoxButtons.OK, MessageBoxIcon.Error);
88 }
89 catch (Exception ex)
90 {
91 MessageBox.Show(ex.ToString(),"Encountered an error while converting the data", MessageBoxButtons.OK, MessageBoxIcon.Error);
92 }
93 }
94
95 private void ConvertData(string value, int FromBase)
96 {
97 // binary
98 if (txtInput.InputType != NumericInputTypes.Binary)
99 {
100 int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
101 txtBinary.Value = Convert.ToString(val, 2);
102 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
103 //{
104 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
105 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
106 // converter.HexFloat = val2;
107 // txtBinary.Value = Convert.ToString(converter.Float);
108 //}
109 }
110 // decimal
111 if (txtInput.InputType != NumericInputTypes.Decimal)
112 {
113 int val = Convert.ToInt32(value, FromBase);
114 txtDecimal.Value = Convert.ToString(val, 10);
115 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
116 //{
117 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
118 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
119 // converter.HexFloat = val2;
120 // txtDecimal.Value = string.Format("{0:R}", converter.Float);
121 //}
122 }
123 // hex
124 if (txtInput.InputType != NumericInputTypes.Hex)
125 {
126 int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
127 txtHex.Value = Convert.ToString(val, 16);
128 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
129 //{
130 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
131 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
132 // converter.HexFloat = val2;
133 //}
134 }
135 // octal
136 if (txtInput.InputType != NumericInputTypes.Octal)
137 {
138 int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
139 txtOctal.Value = Convert.ToString(val, 8);
140 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
141 //{
142 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
143 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
144 // converter.HexFloat = val2;
145 //}
146 }
147 //// float
148 //if (txtInput.InputType != NumericInputTypes.IEEE754HexFloat)
149 //{
150 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
151 // uint val = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
152 // float f = Convert.ToSingle(val);
153 // converter.Float = f;
154 // //txtFloat.Value = string.Format("{0:R}", converter.Float);
155 // txtFloat.Value = string.Format("0x{0:x8}", converter.HexFloat);
156 //}
157 }
158 }
159 }

  ViewVC Help
Powered by ViewVC 1.1.22