ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/FloatingDataTypeConverter.cs
(Generate patch)

Comparing trunk/RomCheater/Docking/FloatingDataTypeConverter.cs (file contents):
Revision 224 by william, Sat Jun 2 13:20:13 2012 UTC vs.
Revision 225 by william, Sat Jun 2 14:29:00 2012 UTC

# Line 7 | Line 7 | 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   {
# Line 21 | Line 22 | namespace RomCheater.Docking
22          private void chkBinary_CheckedChanged(object sender, EventArgs e)
23          {
24              // binary input
25 <            txtInput.InputType = MultiNumericBox_InputType.Binary;
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 = MultiNumericBox_InputType.Decimal;
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 = MultiNumericBox_InputType.Hex;
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 = MultiNumericBox_InputType.Octal;
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 = MultiNumericBox_InputType.IEEE754HexFloat;
53 >            txtInput.InputType = NumericInputTypes.IEEE754HexFloat;
54 >            txtInput.Value = (0).ToString();
55 >        }
56 >
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      }
148   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines