/Files/zerobug/Demisemiquaver.zip三十二进制类,合法字符0-9,A-V,遇V进位。目前支持加法。
----------------------------------------------------------------
Code
1/**//**************************************************************************
2 * COPYRIGHT (C) 2007, SHANG GROUP. ALL RIGHTS RESERVED.
3 * FILENAME : Demisemiquaver.cs
4 * DESCRIPTION: 三十二进制类,可进行加法。
5 * 1.合法的字符包括0-9,A-V;
6 * 2.a-v字符会自动转为A-V;
7 * AUTHOR : ZEROBUG
8 * DATE : May 26, 2008
9 * VERSION : 0.1
10 *
11 * - MODIFIED HISTORY -
12 *
13 * 1.May 26, 2008 by Sun G.Q., 0.0 - 0.1
14 * - Created.
15 **************************************************************************/
16
17using System;
18using System.Collections.Generic;
19using System.Text;
20
21namespace Util
22{
23 /**//// <summary>
24 /// 自定义三十二进制,包括加法
25 /// </summary>
26 public class Demisemiquaver
27 {
28 private String _value;
29
30 public Demisemiquaver()
31 {
32
33 }
34 public Demisemiquaver(String v)
35 {
36 this.Value = v;
37 }
38 public String Value
39 {
40 get{ return _value; }
41 set
42 {
43 if (CheckString(value.ToUpper()))
44 _value = value.ToUpper();
45 else
46 throw (new ArgumentOutOfRangeException("Value", value, "Value must be assigned a string which includes the chars between '0-9' or 'A-V'."));
47 }
48 }
49
50 三十二进制加法#region 三十二进制加法
51 /**//// <summary>
52 /// 三十二进制加法,自增1
53 /// </summary>
54 /// <param name="oldValue"></param>
55 /// <returns></returns>
56 public static String Add(String oldValue)
57 {
58 return Add(oldValue, "1");
59 }
60
61 /**//// <summary>
62 /// 三十二进制加法
63 /// </summary>
64 /// <param name="oldValue"></param>
65 /// <param name="addValue"></param>
66 /// <returns></returns>
67 public static String Add(String oldValue, String addValue)
68 {
69 //检查字符合法性
70 if (!CheckString(oldValue.ToUpper()))
71 throw (new ArgumentOutOfRangeException("oldValue", oldValue, "Value must be assigned a string which includes the chars between '0-9' or 'A-V'."));
72 if (!CheckString(addValue.ToUpper()))
73 throw (new ArgumentOutOfRangeException("addValue", addValue, "Value must be assigned a string which includes the chars between '0-9' or 'A-V'."));
74
75
76 Int32 len1 = oldValue.Length;
77 Int32 len2 = addValue.Length;
78 Int32 cr = 0;
79 Int32 g = 0;
80
81 String add = String.Empty;
82
83 Char[] olds = oldValue.ToUpper().ToCharArray();
84 Char[] adds = addValue.ToUpper().ToCharArray();
85
86 //以长字符串为主
87 if (len1 > len2)
88 {
89 //先与短字符串相加
90 for (Int32 i = len2 - 1; i >= 0; i--)
91 {
92 g = AddChar(Convert32To10((Int32)olds[i + len1 - len2]), Convert32To10((Int32)adds[i]), cr, out cr);
93 add = Convert10To32(g, true) + add;
94 }
95 //进位并把长字符串的高位连接上
96 Int32 j = len1 - len2 - 1;
97 while (j >= 0)
98 {
99 g = AddChar(Convert32To10((Int32)olds[j]), cr, out cr);
100 add = Convert10To32(g, true) + add;
101 j--;
102 }
103 }
104 else if (len2 > len1)
105 {
106 for (Int32 i = len1 - 1; i >= 0; i--)
107 {
108 g = AddChar(Convert32To10((Int32)adds[i + len2 - len1]), Convert32To10((Int32)olds[i]), cr, out cr);
109 add = Convert10To32(g, true) + add;
110 }
111 Int32 j = len2 - len1 - 1;
112 while (j >= 0)
113 {
114 g = AddChar(Convert32To10((Int32)adds[j]), cr, out cr);
115 add = Convert10To32(g, true) + add;
116 j--;
117 }
118 }
119 else if (len1 == len2)
120 {
121 for (Int32 i = len1 - 1; i >= 0; i--)
122 {
123 g = AddChar(Convert32To10((Int32)adds[i + len2 - len1]), Convert32To10((Int32)olds[i]), cr, out cr);
124 add = Convert10To32(g, true) + add;
125 }
126
127 //g = AddChar(Convert32To10((Int32)adds[0]), cr, out cr);
128 if (cr > 0)
129 add = Convert10To32(cr, true) + add;
130
131 }
132
133 return add;
134 }
135 #endregion
136
137 2,10进制转为32进制,合法字符包括'1-9','A-V'#region 2,10进制转为32进制,合法字符包括'1-9','A-V'
138 /**//// <summary>
139 /// 十进制转换为32进制:先转换为2进制, 再按照5位划分,转换为32进制
140 /// </summary>
141 /// <param name="Dec"></param>
142 /// <returns></returns>
143 public static String Convert10To32(Int32 Dec)
144 {
145 String dt2 = Convert.ToString(Dec, 2);
146 String s32 = String.Empty;
147
148 /**//
149 //如果2进制的长度是5的整数倍时,直接按5位划分计算,
150 //否则,先从高位(左起)取余数位,再按5位划分计算
151 /**/
152 Int32 iRest = dt2.Length % 5;
153
154 if (iRest == 0)
155 {
156 for (Int32 i = 0; i < dt2.Length / 5; i++)
157 {
158 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
159 }
160 }
161 else
162 {
163 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(0, iRest)), 2), true);
164
165 dt2 = dt2.Substring(iRest, dt2.Length - iRest);
166
167 for (Int32 i = 0; i < dt2.Length / 5; i++)
168 {
169 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
170 }
171 }
172 return s32;
173 }
174
175 /**//// <summary>
176 /// 二进制转换为32进制:按照5位划分,转换为32进制
177 /// </summary>
178 /// <param name="Dec"></param>
179 /// <returns></returns>
180 public static String Convert2To32(String s2)
181 {
182 String dt2 = s2;
183 String s32 = String.Empty;
184
185 /**//
186 //如果2进制的长度是5的整数倍时,直接按5位划分计算,
187 //否则,先从高位(左起)取余数位,再按5位划分计算
188 /**/
189 Int32 iRest = dt2.Length % 5;
190
191 if (iRest == 0)
192 {
193 for (Int32 i = 0; i < dt2.Length / 5; i++)
194 {
195 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
196 }
197 }
198 else
199 {
200 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(0, iRest)), 2), true);
201
202 dt2 = dt2.Substring(iRest, dt2.Length - iRest);
203
204 for (Int32 i = 0; i < dt2.Length / 5; i++)
205 {
206 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
207 }
208 }
209 return s32;
210 }
211
212 /**//// <summary>
213 /// 将小于32的10进制数,转换为32进制
214 /// </summary>
215 /// <param name="s10"></param>
216 /// <returns></returns>
217 public static String Convert10To32(Int32 dec, Boolean IsLessThan32)
218 {
219
220 String s = String.Empty;
221 if (IsLessThan32)
222 {
223 String s10 = dec.ToString();
224 if (s10.Length == 1)
225 {
226 s = s10;
227
228 }
229 else if (Convert.ToInt32(s10) < 32)
230 {
231 s = Convert.ToString((Char)(64 + (dec - 9)));
232
233 }
234 }
235 return s;
236 }
237
238 #endregion
239
240 检查合法性,合法字符包括‘0-9’,‘A-V'#region 检查合法性,合法字符包括‘0-9’,‘A-V'
241 /**//// <summary>
242 /// 检查字符是否合法,合法字符包括‘0-9’,‘A-V'
243 /// </summary>
244 /// <param name="c"></param>
245 /// <returns></returns>
246 public static Boolean CheckChar(Char c)
247 {
248 if ((Int32)c < 48 || ((Int32)c > 57 && (Int32)c < 65) || (Int32)c > 86)
249 return false;
250 else
251 return true;
252 }
253
254 /**//// <summary>
255 /// 检查字符串的组成字符是否合法,合法字符包括‘0-9’,‘A-V'
256 /// </summary>
257 /// <param name="s"></param>
258 /// <returns></returns>
259 public static Boolean CheckString(String s)
260 {
261 Boolean IsOK = true;
262 Char[] cs = s.ToCharArray();
263 for (Int32 i = 0; i < s.Length; i++)
264 {
265 if (!CheckChar(cs[i]))
266 {
267 IsOK = false;
268 break;
269 }
270 }
271 return IsOK;
272 }
273 #endregion
274
275 字符相加#region 字符相加
276 /**//// <summary>
277 /// 把两个字符相加,并输出进位的字符
278 /// </summary>
279 /// <param name="c1"></param>
280 /// <param name="c2"></param>
281 /// <param name="cr"></param>
282 /// <returns></returns>
283 public static Int32 AddChar(Int32 c1, Int32 c2, out Int32 cr)
284 {
285
286 Int32 a = c1 + c2;
287 if (a < 32)
288 {
289 cr = 0;
290 return a;
291 }
292 else
293 {
294 cr = 1;
295 return a-32;
296 }
297 }
298
299 /**//// <summary>
300 /// 把三个字符相加,并输出进位的字符cr
301 /// </summary>
302 /// <param name="c1"></param>
303 /// <param name="c2"></param>
304 /// <param name="c3"></param>
305 /// <param name="cr">进位</param>
306 /// <returns></returns>
307 public static Int32 AddChar(Int32 c1, Int32 c2, Int32 c3, out Int32 cr)
308 {
309 //0-96
310 Int32 a = c1 + c2 + c3;
311 if (a < 32)
312 {
313 cr = 0;
314 return a;
315 }
316 else if (a < 64)
317 {
318 cr = 1;
319 return a - 32;
320 }
321 else
322 {
323 cr = 2;
324 return a - 64;
325 }
326 }
327 #endregion
328
329 三十二进制转为10,2进制#region 三十二进制转为10,2进制
330 /**//// <summary>
331 /// 三十二进制的字符(值)转为10进制
332 /// </summary>
333 /// <param name="c"></param>
334 /// <returns></returns>
335 public static Int32 Convert32To10(Int32 c)
336 {
337
338 Int32 iSubtract = 0;
339 if (c > 47 && c < 58)
340 {
341 iSubtract = (c - 48);
342 }
343 else if (c > 64 && c < 87)
344 {
345 iSubtract = (c - 64 + 9);
346 }
347 return iSubtract;
348
349 }
350
351 /**//// <summary>
352 /// 三十二进制的字符串转为10进制,转之前要确认为有效的10进制
353 /// </summary>
354 /// <param name="s"></param>
355 /// <returns></returns>
356 public static Int32 Convert32To10(String s)
357 {
358 /**///
359 Int32 ii = 0;
360 return ii;
361 }
362
363 /**//// <summary>
364 /// 三十二进制的字符串转为2进制,转之前要确认为有效的2进制
365 /// </summary>
366 /// <param name="s"></param>
367 /// <returns></returns>
368 public static String Convert32To2(String s)
369 {
370 /**///
371 String ss = String.Empty;
372 return ss;
373 }
374 #endregion
375
376 }
377
378}
379
1/**//**************************************************************************
2 * COPYRIGHT (C) 2007, SHANG GROUP. ALL RIGHTS RESERVED.
3 * FILENAME : Demisemiquaver.cs
4 * DESCRIPTION: 三十二进制类,可进行加法。
5 * 1.合法的字符包括0-9,A-V;
6 * 2.a-v字符会自动转为A-V;
7 * AUTHOR : ZEROBUG
8 * DATE : May 26, 2008
9 * VERSION : 0.1
10 *
11 * - MODIFIED HISTORY -
12 *
13 * 1.May 26, 2008 by Sun G.Q., 0.0 - 0.1
14 * - Created.
15 **************************************************************************/
16
17using System;
18using System.Collections.Generic;
19using System.Text;
20
21namespace Util
22{
23 /**//// <summary>
24 /// 自定义三十二进制,包括加法
25 /// </summary>
26 public class Demisemiquaver
27 {
28 private String _value;
29
30 public Demisemiquaver()
31 {
32
33 }
34 public Demisemiquaver(String v)
35 {
36 this.Value = v;
37 }
38 public String Value
39 {
40 get{ return _value; }
41 set
42 {
43 if (CheckString(value.ToUpper()))
44 _value = value.ToUpper();
45 else
46 throw (new ArgumentOutOfRangeException("Value", value, "Value must be assigned a string which includes the chars between '0-9' or 'A-V'."));
47 }
48 }
49
50 三十二进制加法#region 三十二进制加法
51 /**//// <summary>
52 /// 三十二进制加法,自增1
53 /// </summary>
54 /// <param name="oldValue"></param>
55 /// <returns></returns>
56 public static String Add(String oldValue)
57 {
58 return Add(oldValue, "1");
59 }
60
61 /**//// <summary>
62 /// 三十二进制加法
63 /// </summary>
64 /// <param name="oldValue"></param>
65 /// <param name="addValue"></param>
66 /// <returns></returns>
67 public static String Add(String oldValue, String addValue)
68 {
69 //检查字符合法性
70 if (!CheckString(oldValue.ToUpper()))
71 throw (new ArgumentOutOfRangeException("oldValue", oldValue, "Value must be assigned a string which includes the chars between '0-9' or 'A-V'."));
72 if (!CheckString(addValue.ToUpper()))
73 throw (new ArgumentOutOfRangeException("addValue", addValue, "Value must be assigned a string which includes the chars between '0-9' or 'A-V'."));
74
75
76 Int32 len1 = oldValue.Length;
77 Int32 len2 = addValue.Length;
78 Int32 cr = 0;
79 Int32 g = 0;
80
81 String add = String.Empty;
82
83 Char[] olds = oldValue.ToUpper().ToCharArray();
84 Char[] adds = addValue.ToUpper().ToCharArray();
85
86 //以长字符串为主
87 if (len1 > len2)
88 {
89 //先与短字符串相加
90 for (Int32 i = len2 - 1; i >= 0; i--)
91 {
92 g = AddChar(Convert32To10((Int32)olds[i + len1 - len2]), Convert32To10((Int32)adds[i]), cr, out cr);
93 add = Convert10To32(g, true) + add;
94 }
95 //进位并把长字符串的高位连接上
96 Int32 j = len1 - len2 - 1;
97 while (j >= 0)
98 {
99 g = AddChar(Convert32To10((Int32)olds[j]), cr, out cr);
100 add = Convert10To32(g, true) + add;
101 j--;
102 }
103 }
104 else if (len2 > len1)
105 {
106 for (Int32 i = len1 - 1; i >= 0; i--)
107 {
108 g = AddChar(Convert32To10((Int32)adds[i + len2 - len1]), Convert32To10((Int32)olds[i]), cr, out cr);
109 add = Convert10To32(g, true) + add;
110 }
111 Int32 j = len2 - len1 - 1;
112 while (j >= 0)
113 {
114 g = AddChar(Convert32To10((Int32)adds[j]), cr, out cr);
115 add = Convert10To32(g, true) + add;
116 j--;
117 }
118 }
119 else if (len1 == len2)
120 {
121 for (Int32 i = len1 - 1; i >= 0; i--)
122 {
123 g = AddChar(Convert32To10((Int32)adds[i + len2 - len1]), Convert32To10((Int32)olds[i]), cr, out cr);
124 add = Convert10To32(g, true) + add;
125 }
126
127 //g = AddChar(Convert32To10((Int32)adds[0]), cr, out cr);
128 if (cr > 0)
129 add = Convert10To32(cr, true) + add;
130
131 }
132
133 return add;
134 }
135 #endregion
136
137 2,10进制转为32进制,合法字符包括'1-9','A-V'#region 2,10进制转为32进制,合法字符包括'1-9','A-V'
138 /**//// <summary>
139 /// 十进制转换为32进制:先转换为2进制, 再按照5位划分,转换为32进制
140 /// </summary>
141 /// <param name="Dec"></param>
142 /// <returns></returns>
143 public static String Convert10To32(Int32 Dec)
144 {
145 String dt2 = Convert.ToString(Dec, 2);
146 String s32 = String.Empty;
147
148 /**//
149 //如果2进制的长度是5的整数倍时,直接按5位划分计算,
150 //否则,先从高位(左起)取余数位,再按5位划分计算
151 /**/
152 Int32 iRest = dt2.Length % 5;
153
154 if (iRest == 0)
155 {
156 for (Int32 i = 0; i < dt2.Length / 5; i++)
157 {
158 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
159 }
160 }
161 else
162 {
163 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(0, iRest)), 2), true);
164
165 dt2 = dt2.Substring(iRest, dt2.Length - iRest);
166
167 for (Int32 i = 0; i < dt2.Length / 5; i++)
168 {
169 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
170 }
171 }
172 return s32;
173 }
174
175 /**//// <summary>
176 /// 二进制转换为32进制:按照5位划分,转换为32进制
177 /// </summary>
178 /// <param name="Dec"></param>
179 /// <returns></returns>
180 public static String Convert2To32(String s2)
181 {
182 String dt2 = s2;
183 String s32 = String.Empty;
184
185 /**//
186 //如果2进制的长度是5的整数倍时,直接按5位划分计算,
187 //否则,先从高位(左起)取余数位,再按5位划分计算
188 /**/
189 Int32 iRest = dt2.Length % 5;
190
191 if (iRest == 0)
192 {
193 for (Int32 i = 0; i < dt2.Length / 5; i++)
194 {
195 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
196 }
197 }
198 else
199 {
200 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(0, iRest)), 2), true);
201
202 dt2 = dt2.Substring(iRest, dt2.Length - iRest);
203
204 for (Int32 i = 0; i < dt2.Length / 5; i++)
205 {
206 s32 = s32 + Convert10To32(Convert.ToInt32((dt2.Substring(i * 5, 5)), 2), true);
207 }
208 }
209 return s32;
210 }
211
212 /**//// <summary>
213 /// 将小于32的10进制数,转换为32进制
214 /// </summary>
215 /// <param name="s10"></param>
216 /// <returns></returns>
217 public static String Convert10To32(Int32 dec, Boolean IsLessThan32)
218 {
219
220 String s = String.Empty;
221 if (IsLessThan32)
222 {
223 String s10 = dec.ToString();
224 if (s10.Length == 1)
225 {
226 s = s10;
227
228 }
229 else if (Convert.ToInt32(s10) < 32)
230 {
231 s = Convert.ToString((Char)(64 + (dec - 9)));
232
233 }
234 }
235 return s;
236 }
237
238 #endregion
239
240 检查合法性,合法字符包括‘0-9’,‘A-V'#region 检查合法性,合法字符包括‘0-9’,‘A-V'
241 /**//// <summary>
242 /// 检查字符是否合法,合法字符包括‘0-9’,‘A-V'
243 /// </summary>
244 /// <param name="c"></param>
245 /// <returns></returns>
246 public static Boolean CheckChar(Char c)
247 {
248 if ((Int32)c < 48 || ((Int32)c > 57 && (Int32)c < 65) || (Int32)c > 86)
249 return false;
250 else
251 return true;
252 }
253
254 /**//// <summary>
255 /// 检查字符串的组成字符是否合法,合法字符包括‘0-9’,‘A-V'
256 /// </summary>
257 /// <param name="s"></param>
258 /// <returns></returns>
259 public static Boolean CheckString(String s)
260 {
261 Boolean IsOK = true;
262 Char[] cs = s.ToCharArray();
263 for (Int32 i = 0; i < s.Length; i++)
264 {
265 if (!CheckChar(cs[i]))
266 {
267 IsOK = false;
268 break;
269 }
270 }
271 return IsOK;
272 }
273 #endregion
274
275 字符相加#region 字符相加
276 /**//// <summary>
277 /// 把两个字符相加,并输出进位的字符
278 /// </summary>
279 /// <param name="c1"></param>
280 /// <param name="c2"></param>
281 /// <param name="cr"></param>
282 /// <returns></returns>
283 public static Int32 AddChar(Int32 c1, Int32 c2, out Int32 cr)
284 {
285
286 Int32 a = c1 + c2;
287 if (a < 32)
288 {
289 cr = 0;
290 return a;
291 }
292 else
293 {
294 cr = 1;
295 return a-32;
296 }
297 }
298
299 /**//// <summary>
300 /// 把三个字符相加,并输出进位的字符cr
301 /// </summary>
302 /// <param name="c1"></param>
303 /// <param name="c2"></param>
304 /// <param name="c3"></param>
305 /// <param name="cr">进位</param>
306 /// <returns></returns>
307 public static Int32 AddChar(Int32 c1, Int32 c2, Int32 c3, out Int32 cr)
308 {
309 //0-96
310 Int32 a = c1 + c2 + c3;
311 if (a < 32)
312 {
313 cr = 0;
314 return a;
315 }
316 else if (a < 64)
317 {
318 cr = 1;
319 return a - 32;
320 }
321 else
322 {
323 cr = 2;
324 return a - 64;
325 }
326 }
327 #endregion
328
329 三十二进制转为10,2进制#region 三十二进制转为10,2进制
330 /**//// <summary>
331 /// 三十二进制的字符(值)转为10进制
332 /// </summary>
333 /// <param name="c"></param>
334 /// <returns></returns>
335 public static Int32 Convert32To10(Int32 c)
336 {
337
338 Int32 iSubtract = 0;
339 if (c > 47 && c < 58)
340 {
341 iSubtract = (c - 48);
342 }
343 else if (c > 64 && c < 87)
344 {
345 iSubtract = (c - 64 + 9);
346 }
347 return iSubtract;
348
349 }
350
351 /**//// <summary>
352 /// 三十二进制的字符串转为10进制,转之前要确认为有效的10进制
353 /// </summary>
354 /// <param name="s"></param>
355 /// <returns></returns>
356 public static Int32 Convert32To10(String s)
357 {
358 /**///
359 Int32 ii = 0;
360 return ii;
361 }
362
363 /**//// <summary>
364 /// 三十二进制的字符串转为2进制,转之前要确认为有效的2进制
365 /// </summary>
366 /// <param name="s"></param>
367 /// <returns></returns>
368 public static String Convert32To2(String s)
369 {
370 /**///
371 String ss = String.Empty;
372 return ss;
373 }
374 #endregion
375
376 }
377
378}
379