c++和java字节高低位的转换

c++和java字节高低位的转换

ID:39549625

大小:51.50 KB

页数:5页

时间:2019-07-06

c++和java字节高低位的转换_第1页
c++和java字节高低位的转换_第2页
c++和java字节高低位的转换_第3页
c++和java字节高低位的转换_第4页
c++和java字节高低位的转换_第5页
资源描述:

《c++和java字节高低位的转换》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、c++和java字节高低位的转换现在我们需要从一个C/C++语言生成的二进制文件中读出一个float数据 1.// 参见java.io.DataInputStream  2.// C++写入的字节顺序是从低到高(左低到右高),  3.   而java.io.DataInputStream读取的数据是从高到低(左高到右低)  4.// 所以需要自己改写一下  5.// 功能和java.io.DataInputStream类似的  6.public class CppInputStream exten

2、ds FilterInputStream {  7.  8.  public CppInputStream(InputStream in) {  9.    super(in);  10.  }  11.  public final int read(byte b[]) throws IOException {  12.    return in.read(b, 0, b.length);  13.  }  14.  15.  public final int read(byte b[], int

3、 off, int len) throws IOException {  16.    return in.read(b, off, len);  17.  }  18.  19.  public final void readFully(byte b[]) throws IOException {  20.    readFully(b, 0, b.length);  21.  }  22.  23.  public final void readFully(byte b[], int off,

4、 int len) throws IOException {  24.    if (len < 0)  25.      throw new IndexOutOfBoundsException();  26.    int n = 0;  27.    while (n < len) {  28.      int count = in.read(b, off + n, len - n);  29.      if (count < 0)  30.        throw new EOFExc

5、eption();  31.      n += count;  32.    }  33.  }  34.  35.  public final int skipBytes(int n) throws IOException {  36.    int total = 0;  37.    int cur = 0;  38.    while ((total < n) && ((cur = (int) in.skip(n - total)) > 0)) {  1.      total += c

6、ur;  2.    }  3.    return total;  4.  }  5.  6.  public final byte readByte() throws IOException {  7.    int ch = in.read();  8.    if (ch < 0)  9.      throw new EOFException();  10.    return (byte) (ch);  11.  }  12.  13.  public final int readUn

7、signedByte() throws IOException {  14.    int ch = in.read();  15.    if (ch < 0)  16.      throw new EOFException();  17.    return ch;  18.  }  19.  20.  public final short readShort() throws IOException {  21.    int ch2 = in.read();  22.    int ch

8、1 = in.read();  23.    if ((ch1 

9、 ch2) < 0)  24.      throw new EOFException();  25.    return (short) ((ch1 << 8) + (ch2 << 0));  26.  }  27.  28.  public final int readUnsignedShort() throws IOException {  29.    int ch2 = in.read();  30.   

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。