1 |
william |
218 |
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 |
william |
225 |
using libWin32.Win32.NumericConversion.IEEE754; |
11 |
william |
218 |
|
12 |
|
|
namespace RomCheater.Docking |
13 |
|
|
{ |
14 |
|
|
public partial class FloatingDataTypeConverter : DockContent |
15 |
|
|
{ |
16 |
|
|
public FloatingDataTypeConverter() |
17 |
|
|
{ |
18 |
|
|
InitializeComponent(); |
19 |
william |
223 |
chkhexadecimal.Checked = true; |
20 |
william |
218 |
} |
21 |
william |
222 |
|
22 |
|
|
private void chkBinary_CheckedChanged(object sender, EventArgs e) |
23 |
|
|
{ |
24 |
william |
223 |
// binary input |
25 |
william |
225 |
txtInput.InputType = NumericInputTypes.Binary; |
26 |
|
|
txtInput.Value = (0).ToString(); |
27 |
william |
223 |
} |
28 |
william |
222 |
|
29 |
william |
223 |
private void chkdecimal_CheckedChanged(object sender, EventArgs e) |
30 |
|
|
{ |
31 |
|
|
// decimal input |
32 |
william |
225 |
txtInput.InputType = NumericInputTypes.Decimal; |
33 |
|
|
txtInput.Value = (0).ToString(); |
34 |
william |
222 |
} |
35 |
william |
223 |
|
36 |
|
|
private void chkhexadecimal_CheckedChanged(object sender, EventArgs e) |
37 |
|
|
{ |
38 |
|
|
// hex input |
39 |
william |
225 |
txtInput.InputType = NumericInputTypes.Hex; |
40 |
|
|
txtInput.Value = (0).ToString(); |
41 |
william |
223 |
} |
42 |
|
|
|
43 |
|
|
private void chkoctal_CheckedChanged(object sender, EventArgs e) |
44 |
|
|
{ |
45 |
|
|
// octal input |
46 |
william |
225 |
txtInput.InputType = NumericInputTypes.Octal; |
47 |
|
|
txtInput.Value = (0).ToString(); |
48 |
william |
223 |
} |
49 |
|
|
|
50 |
|
|
private void chkieee754float_CheckedChanged(object sender, EventArgs e) |
51 |
|
|
{ |
52 |
|
|
// IEEE754 Hex Float (hex) |
53 |
william |
225 |
txtInput.InputType = NumericInputTypes.IEEE754HexFloat; |
54 |
|
|
txtInput.Value = (0).ToString(); |
55 |
william |
223 |
} |
56 |
william |
225 |
|
57 |
|
|
private void btnConvert_Click(object sender, EventArgs e) |
58 |
|
|
{ |
59 |
|
|
switch (txtInput.InputType) |
60 |
|
|
{ |
61 |
|
|
case NumericInputTypes.Binary: |
62 |
|
|
txtBinary.Value = txtInput.Value; |
63 |
|
|
ConvertData(txtBinary.Value, 2); |
64 |
|
|
break; |
65 |
|
|
case NumericInputTypes.Decimal: |
66 |
|
|
txtDecimal.Value = txtInput.Value; |
67 |
|
|
ConvertData(txtDecimal.Value, 10); |
68 |
|
|
break; |
69 |
|
|
case NumericInputTypes.Hex: |
70 |
|
|
txtHex.Value = txtInput.Value; |
71 |
|
|
ConvertData(txtHex.Value, 16); |
72 |
|
|
break; |
73 |
|
|
case NumericInputTypes.IEEE754HexFloat: |
74 |
|
|
txtFloat.Value = txtInput.Value; |
75 |
|
|
ConvertData(txtFloat.Value, 16); |
76 |
|
|
break; |
77 |
|
|
case NumericInputTypes.Octal: |
78 |
|
|
txtOctal.Value = (txtInput.Value.StartsWith("0")) ? txtInput.Value : string.Format("0{0}",txtInput.Value); |
79 |
|
|
ConvertData(txtOctal.Value, 8); |
80 |
|
|
break; |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
private void ConvertData(string value, int FromBase) |
85 |
|
|
{ |
86 |
|
|
// binary |
87 |
|
|
if (txtInput.InputType != NumericInputTypes.Binary) |
88 |
|
|
{ |
89 |
|
|
int val = Convert.ToInt32(value, FromBase); |
90 |
|
|
txtBinary.Value = Convert.ToString(val, 2); |
91 |
|
|
if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) |
92 |
|
|
{ |
93 |
|
|
ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); |
94 |
|
|
uint val2 = Convert.ToUInt32(value, FromBase); |
95 |
|
|
converter.HexFloat = val2; |
96 |
|
|
txtBinary.Value = Convert.ToString(converter.Float); |
97 |
|
|
} |
98 |
|
|
} |
99 |
|
|
// decimal |
100 |
|
|
if (txtInput.InputType != NumericInputTypes.Decimal) |
101 |
|
|
{ |
102 |
|
|
int val = Convert.ToInt32(value, FromBase); |
103 |
|
|
txtDecimal.Value = Convert.ToString(val, 10); |
104 |
|
|
if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) |
105 |
|
|
{ |
106 |
|
|
ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); |
107 |
|
|
uint val2 = Convert.ToUInt32(value, FromBase); |
108 |
|
|
converter.HexFloat = val2; |
109 |
|
|
txtDecimal.Value = string.Format("{0:R}", converter.Float); |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
// hex |
113 |
|
|
if (txtInput.InputType != NumericInputTypes.Hex) |
114 |
|
|
{ |
115 |
|
|
int val = Convert.ToInt32(value, FromBase); |
116 |
|
|
txtHex.Value = Convert.ToString(val, 16); |
117 |
|
|
if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) |
118 |
|
|
{ |
119 |
|
|
ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); |
120 |
|
|
uint val2 = Convert.ToUInt32(value, FromBase); |
121 |
|
|
converter.HexFloat = val2; |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
// octal |
125 |
|
|
if (txtInput.InputType != NumericInputTypes.Octal) |
126 |
|
|
{ |
127 |
|
|
int val = Convert.ToInt32(value, FromBase); |
128 |
|
|
txtOctal.Value = Convert.ToString(val, 8); |
129 |
|
|
if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat) |
130 |
|
|
{ |
131 |
|
|
ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); |
132 |
|
|
uint val2 = Convert.ToUInt32(value, FromBase); |
133 |
|
|
converter.HexFloat = val2; |
134 |
|
|
} |
135 |
|
|
} |
136 |
|
|
// float |
137 |
|
|
if (txtInput.InputType != NumericInputTypes.IEEE754HexFloat) |
138 |
|
|
{ |
139 |
|
|
ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter(); |
140 |
|
|
uint val = Convert.ToUInt32(value, FromBase); |
141 |
|
|
float f = Convert.ToSingle(val); |
142 |
|
|
converter.Float = f; |
143 |
|
|
//txtFloat.Value = string.Format("{0:R}", converter.Float); |
144 |
|
|
txtFloat.Value = string.Format("0x{0:x8}", converter.HexFloat); |
145 |
|
|
} |
146 |
|
|
} |
147 |
william |
218 |
} |
148 |
|
|
} |