当前位置:编程学习 > JAVA >>

aspx代码改为java代码?

下面是aspx代码,在java里面,大于128小于256的整数要强制转换?
帮忙实现下面的功能,用java代码来改写;

  long bigid = 10151;   
  long smid  = 3721;
  byte[] byteArray = { 0x00, 0x00, 0x0e, 0x89, 0x00, 0x00, 0x27, 0xa7 };
  // write bigid
  byte[] intByte = System.BitConverter.GetBytes(bigid);
  byteArray[0] = intByte[3];
  byteArray[1] = intByte[2];
  byteArray[2] = intByte[1];
  byteArray[3] = intByte[0];
  // write smid
  intByte = System.BitConverter.GetBytes(smid);
  byteArray[4] = intByte[3];
  byteArray[5] = intByte[2];
  byteArray[6] = intByte[1];
  byteArray[7] = intByte[0];
/////////////////////////////////////////////////
  Stream dataStream =...;
  BinaryReader BR = new BinaryReader(dataStream);
  // skip 3 byte
  BR.ReadByte();
  BR.ReadByte();
  BR.ReadByte();
  if (0 == BR.ReadInt32())
  {
          byte[] tmpByte = new byte[4];
          tmpByte[3] = BR.ReadByte();
          tmpByte[2] = BR.ReadByte();
          tmpByte[1] = BR.ReadByte();
          tmpByte[0] = BR.ReadByte();
          int tiia = BitConverter.ToInt32(tmpByte, 0);
          out double tA = (double)tiia / 1000000D;
  }





--------------------编程问答-------------------- byteArray = { 0x00, 0x00, 0x0e, 0x89, 0x00, 0x00, 0x27, 0xa7 };
其实前4位是3721,后四位数10151;
0x0e=14,0x89=137;14*256+137=3721;
0x27=39,0xa7=167;39*256+167=10151;

--------------------编程问答-------------------- 实现什么呢?这只是一个代码块,也没任何输入值和返回值 --------------------编程问答-------------------- 以上其实就是分2部分代码块:
------------------------------------------
第一部分是把 
   long bigid = 10151;   
  long smid  = 3721;
转换为字节数组放到byteArray中,就好了;
----------------------------------------------
第二部分是把
   stream 流中的数据跳过3个字节,依次读4个byte到temByte中,然后把temByte转换成double就可以了;
--------------------编程问答-------------------- 在java里面,byte是从-128到127,
00000001-------(+1)
01111111-------(+127)
00000000--------(0)
10000000-------(-1)
11111111-------(-128)
所以在aspx和c里面和java里面是不同的 --------------------编程问答-------------------- 蛋疼。。。 --------------------编程问答-------------------- 没有人回呀
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,