private static void decodeEdifactSegment(BitSource bits,StringBuilder result){
  do {
    if (bits.available() <= 16) {
      return;
    }
    for (int i=0; i < 4; i++) {
      int edifactValue=bits.readBits(6);
      if (edifactValue == 0x1F) {
        int bitsLeft=8 - bits.getBitOffset();
        if (bitsLeft != 8) {
          bits.readBits(bitsLeft);
        }
        return;
      }
      if ((edifactValue & 0x20) == 0) {
        edifactValue|=0x40;
      }
      result.append((char)edifactValue);
    }
  }
 while (bits.available() > 0);
}

private static void decodeEdifactSegment ( BitSource bits , StringBuilder result ) { do { if ( bits . available ( ) <= 16 ) { return ; } for ( int i = 0 ; i < 4 ; i ++ ) { int edifactValue = bits . readBits ( 6 ) ; if ( edifactValue == 0x1F ) { int bitsLeft = 8 - bits . getBitOffset ( ) ; if ( bitsLeft != 8 ) { bits . readBits ( bitsLeft ) ; } return ; } if ( ( edifactValue & 0x20 ) == 0 ) { edifactValue |= 0x40 ; } result . append ( ( char ) edifactValue ) ; } } while ( bits . available ( ) > 0 ) ; }
see iso 16022 : 2006 , 5 . 2 . 8 and annex c table c . 3
