陈嘉乐
2020-01-03 60fea1a35f8bfd2eb1399cae05d853b93b3674f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
namespace Shared
{
    public class Utlis
    {
 
        ///// <summary>
        ///// 将int数值转换为占四个字节的byte数组
        ///// </summary>
        ///// <param name="value"></param>
        ///// <returns></returns>
        //public static byte [] IntToByteArray (int i)
        //{
        //    byte [] result = new byte [4];
        //    // 由高位到低位  
        //    result [0] = (byte)((i >> 24) & 0xFF);
        //    result [1] = (byte)((i >> 16) & 0xFF);
        //    result [2] = (byte)((i >> 8) & 0xFF);
        //    result [3] = (byte)(i & 0xFF);
        //    return result;
        //}
 
        ///// <summary>
        ///// byte[]转int 
        ///// </summary>
        ///// <param name="bytes"></param>
        ///// <returns></returns>
        //public static int ByteArrayToInt (byte [] bytes)
        //{
        //    int value = 0;
        //    // 由高位到低位  
        //    for (int i = 0; i < 4; i++) {
        //        int shift = (4 - 1 - i) * 8;
        //        value += (bytes [i] & 0x000000FF) << shift;// 往高位游  
        //    }
        //    return value;
        //}
 
        public static int StringToInt (string mStr) {
            try {
                return int.Parse (mStr);
            } catch {
                return 0;
            }
        }
 
    }
}