乱七八糟

来源:互联网 发布:淘宝有哪些软妹 编辑:程序博客网 时间:2024/05/16 13:57

int  temp = generalParas.get(GeneralParaKey.P1) | generalParas.get(GeneralParaKey.P1) <<1 | generalParas.get(GeneralParaKey.P3) <<2 |

                    generalParas.get(GeneralParaKey.P4) <<3 | generalParas.get(GeneralParaKey.P5) <<4 | generalParas.get(GeneralParaKey.P6)<<5|

                    generalParas.get(GeneralParaKey.P7) <<6;

public class Test {
 public static void main(String[] args) {
  int a=35461;
  System.out.println(Test.byte2int(Test.int2byte(a)));
 }
 
 /**
  * 将int转化成byte[]
  * 
  * @param res 要转化的整数
  * @return 对应的byte[]
  */
 public static byte[] int2byte(int res) {
  byte[] targets = new byte[4];
  targets[0] = (byte) (res & 0xff);// 最低位
  targets[1] = (byte) ((res >> 8) & 0xff);// 次低位
  targets[2] = (byte) ((res >> 16) & 0xff);// 次高位
  targets[3] = (byte) (res >>> 24);// 最高位,无符号右移。
  return targets; 
 } 
 
 /**
  * 将byte[]转化成int
  * @param res 要转化的byte[]
  * @return 对应的整数
  */
 public static int byte2int(byte[] res) { 
  int targets = (res[0] & 0xff) | ((res[1] << 8) & 0xff00) | ((res[2] << 24) >>> 8) | (res[3] << 24); 
  return targets; 
 }

}


原创粉丝点击