whyclj
2020-07-21 04adabbbf34ffdc4b1d49cb5fbc1d57550f98b97
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.base;
 
/**
 * Êý¾Ýת»»
 * @author LiJun
 *
 */
public class ComBase {
    
    
    public static byte changeIntToByte(int data)
    {
        return (byte)(data & 0xFF);
    }
    //------------------------------------------------------------------------------
    public static short changeIntToShort(int data)
    {
        return (short)(data & 0xFFFF);
    }
    //------------------------------------------------------------------------------
    public static byte changeShortToByte(short data)
    {
        return (byte)(data & 0xFF);
    }
    //------------------------------------------------------------------------------
    public static int changeByteToInt(byte data)
    {
        int tmp = data;
        return (tmp & 0xFF);
    }
    //------------------------------------------------------------------------------
    public static int changeShortToInt(short data)
    {
        int tmp = data;
        return (tmp & 0xFFFF);
    }
    //------------------------------------------------------------------------------
    public static double changeShortToDouble(short data)
    {
        int tmp = data & 0xFFFF;
        return (double)(tmp);
    }
    
    public static int ByteToHex(byte temp1 ,byte temp2) {  
        int Rtemp;
        Rtemp = ((temp1 &0xff)<<8) | (temp2 & 0xff);
        return (short)Rtemp;
    } 
     
 
    public static int ByteToHexxx(byte temp1 ,byte temp2) {
        int Rtemp;
        Rtemp = ((temp1 &0xff)<<8) | (temp2 & 0xff);
        return (int)Rtemp;
    } 
 
    public static int ByteToInt(byte temp1 ,byte temp2,byte temp3 ,byte temp4){
        int Rtemp; 
        int Rtemp1,Rtemp2;
        Rtemp = 0;
        Rtemp1 = ByteToHexxx( temp3 ,temp4);
        Rtemp2 = ByteToHexxx( temp1 ,temp2);
        Rtemp= (int)(Rtemp1<<16) +(int)(Rtemp2);
        return Rtemp;
    }
    
    public static long ByteToLong(byte temp1 ,byte temp2,byte temp3 ,byte temp4){
        long Rtemp; 
        long Rtemp1,Rtemp2;
        Rtemp = 0;
        Rtemp1 = ByteToHexxx( temp3 ,temp4);
        Rtemp2 = ByteToHexxx( temp1 ,temp2);
        Rtemp= (int)(Rtemp1<<16) +(int)(Rtemp2);
        return Rtemp;
    }
 
    
    public static byte[] IntToByte(int num){
        byte[]bytes=new byte[4];
        bytes[0]=(byte) ((num>>8)&0xff);
        bytes[1]=(byte) ((num)&0xff);
        bytes[2]=(byte) ((num>>24)&0xff);
        bytes[3]=(byte) (num>>16&0xff);
        return bytes;
    }
    
    public static byte[] LongToByte(long num){
        byte[]bytes=new byte[4];
        bytes[0]=(byte) ((num>>8)&0xff);
        bytes[1]=(byte) ((num)&0xff);
        bytes[2]=(byte) ((num>>24)&0xff);
        bytes[3]=(byte) (num>>16&0xff);
        return bytes;
    }
    
    public static int my_power_2(int N){
        StringBuffer v = new StringBuffer("");
        long num[] = new long[2];
        num[1] = 1;
        if(N > 62){
           num[0] = 1;
           num[0] = num[0]<<(N - 62);
           num[1] = num[1]<<62;
           String s = String.valueOf(num[1]);
           int size = 30,i = 0,j = 0;
           long n[] = new long[size + 1];
           //System.out.println(num[0]+" "+s);
           for(i = s.length() - 1;i >= 0;-- i){
               n[j ++] = (long) (num[0] * (s.charAt(i) - '0'));
               //System.out.println(n[j - 1]);
           }
           for(i = 0;i < size;++ i){
               while(n[i] > 9){
                   n[i + 1] += n[i] / 10;
                   n[i] %= 10;
               }
           }
           boolean bl = false;
           for(i = size;i >= 0;-- i){
               if(n[i] != 0 || bl){
                   v.append(n[i]);
                   bl = true;
               }
           }
        }else{
           num[1] = num[1] << N;
           v.append(String.valueOf(num[1]));
        }   
        return Integer.parseInt(v.toString());
    }
    
}