有一个二进制文件,用16进制记事本打开,内容为:“66 2F 93 00 15 88 D2 02 42 2F 93 00 40 57 01”现要把每个“2F 93”后面的4个数值:“00 15 88 D2”和“00 40 57 01”,找出,并计算其对应的10进制数值,
java如何实现呢?另外,存放“00 15 88 D2”对应的10进制数值的是无符号长整型,在c语言中是__int64或 unsigned long long int,在java中对应何种类型呢? 
谢谢!

解决方案 »

  1.   

    4个字节32 bit,是Java int的长度,但如果需要无符号,则需要升级为long类型才能表示。
      

  2.   

    __int64 对应的就是java的long. 
    但是我看到楼主好象只用了4个字节。 int32_t就够了。
    但是,C写的文件Java不一定能转回来。
      

  3.   

    谢谢大家回帖,我可以先用java的long试一下,请问读取文件中每个“2F 93”后面的4个数值:“00 15 88 D2”和“00 40 57 01”,找出,并计算其对应的10进制数值,在java中如何实现呢?最好能给出java代码,谢谢各位!
      

  4.   

    最好打印出具体数据,分析下结构,然后再操作,主要用到有String.indexOf, String.substring, Long.parseLong
      

  5.   

    short、int、long与byte之间的转换工具类(Java)
    http://blog.csdn.net/afer198215/article/details/6656753
            static void t7(){
    byte[] bys = new byte[]{0x00,0x15,(byte) 0x88,(byte) 0xd2};

    System.out.println(Utility.byte2Int(bys));
    }
      

  6.   

    参考下面的代码,开文件流is之类的代码楼主就自己写了吧。 DataInputStream dis = new DataInputStream( is);
    while (true){
    while (dis.readByte()!=0x2F);
    if (dis.readByte()==(byte)0x93){
    long number = dis.readInt() & 0xFFFFFFFFL;
    System.out.println("找到一个数:" + number);
    }
    }
      

  7.   

    按字节读入文件
    FileInpuetStream fis = new FileInputStream(your_file);
    int c;
    while ((c=fis.read()) != -1) {
        if (c == 0x2a) {
            c = fis.read();
            if (c == -1) {break;}
            if (c == 0x93) {
                byte[] b = new byte[4];
                c = fis.read(b);
                if (c == -1) {break;}
                long l = 0;
                for (int i=0; i<b.length; i++) {
                    l = (l<<4) | b[i]; //不知道存储的是从高位到低位还是低位到高位,LZ自己调整吧
                }
                System.out.println(l);
            }
        }
    }
      

  8.   

    FileInpuetStream fis = new FileInputStream(your_file);
    int c;
    while ((c=fis.read()) != -1) {
        if (c == 0x2F) {
            c = fis.read();
            if (c == -1) {break;}
            if (c == 0x93) {
                byte[] b = new byte[4];
                c = fis.read(b);
                if (c == -1) {break;}
                long l = 0;
                for (int i=0; i<b.length; i++) {
                    l = (l<<4) | b[i]; //不知道存储的是从高位到低位还是低位到高位,LZ自己调整吧
                }
                System.out.println(l);
            }
        }
    }