package com.base;
|
|
/**
|
* Êý¾Ýת»»
|
* @author LiJun
|
*
|
*/
|
public class ComBase {
|
|
|
public static byte changeIntToByte(int data)
|
{
|
return (byte)(data);
|
}
|
//------------------------------------------------------------------------------
|
public static short changeIntToShort(int data)
|
{
|
return (short)(data);
|
}
|
//------------------------------------------------------------------------------
|
public static byte changeShortToByte(short data)
|
{
|
return (byte)(data);
|
}
|
//------------------------------------------------------------------------------
|
public static int changeByteToInt(byte data)
|
{
|
int tmp = data;
|
return (tmp);
|
}
|
//------------------------------------------------------------------------------
|
public static int changeShortToInt(short data)
|
{
|
int tmp = data;
|
return (tmp);
|
}
|
|
/**
|
*
|
* @param data
|
* @param signed true:ÓзûºÅ false:ÎÞ·ûºÅ
|
* @return
|
*/
|
public static int changeShortToInt(short data,boolean signed)
|
{
|
int tmp = data;
|
return !signed?tmp&0xFFFF:tmp;
|
}
|
//------------------------------------------------------------------------------
|
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());
|
}
|
|
}
|