6 Replies Latest reply: Feb 17, 2008 5:50 PM by EJP RSS

    How to get value of 7 bit number?

    807601
      Hi,
      I'm facing trouble in getting the value of 7 bit number.
      It would be 128 base.
      if 7 bits are like that
      0000001 0000010 ----result would be 82

      my code is -

      public static String longTagVal(byte[] bytearr, int start) {
      int k = 0;
      int bits[] = new int[8];
      while(true) {               
      for (int i=0; i<8; i++) {
      bits[i] = (bytearr[start+k] & (0x01 << i)) >> i;                    
      }
      String sum = "";
      for (int i = 0; i <7; i++) {
      sum+=bits[6-i];
      }
      int res = 0;
      byte tt = Byte.parseByte(sum,2);
      for(int i = 0, j = 0 ; i <2 ; i++ , j++) {
      res += Math.pow((double)128, (double)j) * (tt & 0xFF);
      }
      String str = Integer.toHexString(res);
      System.out.println(str);
      k++;
      if(bits[7]== 0) {
      break;}
      }
      return str;
      }