question: public static String adnStringFieldToString ( byte [ ] data , int offset , int length ) { if ( length == 0 ) { return "" ; } if ( length >= 1 ) { if ( data [ offset ] == ( byte ) 0x80 ) { int ucslen = ( length - 1 ) / 2 ; String ret = null ; try { ret = new String ( data , offset + 1 , ucslen * 2 , "utf-16be" ) ; } catch ( UnsupportedEncodingException ex ) { Log . e ( LOG_TAG , "implausible UnsupportedEncodingException" , ex ) ; } if ( ret != null ) { ucslen = ret . length ( ) ; while ( ucslen > 0 && ret . charAt ( ucslen - 1 ) == '' ) ucslen -- ; return ret . substring ( 0 , ucslen ) ; } } } boolean isucs2 = false ; char base = '\0' ; int len = 0 ; if ( length >= 3 && data [ offset ] == ( byte ) 0x81 ) { len = data [ offset + 1 ] & 0xFF ; if ( len > length - 3 ) len = length - 3 ; base = ( char ) ( ( data [ offset + 2 ] & 0xFF ) << 7 ) ; offset += 3 ; isucs2 = true ; } else if ( length >= 4 && data [ offset ] == ( byte ) 0x82 ) { len = data [ offset + 1 ] & 0xFF ; if ( len > length - 4 ) len = length - 4 ; base = ( char ) ( ( ( data [ offset + 2 ] & 0xFF ) << 8 ) | ( data [ offset + 3 ] & 0xFF ) ) ; offset += 4 ; isucs2 = true ; } if ( isucs2 ) { StringBuilder ret = new StringBuilder ( ) ; while ( len > 0 ) { if ( data [ offset ] < 0 ) { ret . append ( ( char ) ( base + ( data [ offset ] & 0x7F ) ) ) ; offset ++ ; len -- ; } int count = 0 ; while ( count < len && data [ offset + count ] >= 0 ) count ++ ; ret . append ( GsmAlphabet . gsm8BitUnpackedToString ( data , offset , count ) ) ; offset += count ; len -= count ; } return ret . toString ( ) ; } Resources resource = Resources . getSystem ( ) ; String defaultCharset = "" ; return GsmAlphabet . gsm8BitUnpackedToString ( data , offset , length , defaultCharset . trim ( ) ) ; }
target:  Decodes a string field that's formatted like the EF[ADN] alpha identifier <p/> From TS 51.011 10.5.1: Coding: this alpha tagging shall use either -    the SMS default 7 bit coded alphabet as defined in TS 23.038 [12] with bit 8 set to 0. The alpha identifier shall be left justified. Unused bytes shall be set to 'FF'; or -    one of the UCS2 coded options as defined in annex B. <p/> Annex B from TS 11.11 V8.13.0: 1)  If the first octet in the alpha string is '80', then the remaining octets are 16 bit UCS2 characters ... 2)  if the first octet in the alpha string is '81', then the second octet contains a value indicating the number of characters in the string, and the third octet contains an 8 bit number which defines bits 15 to 8 of a 16 bit base pointer, where bit 16 is set to zero and bits 7 to 1 are also set to zero.  These sixteen bits constitute a base pointer to a "half page" in the UCS2 code space, to be used with some or all of the remaining octets in the string. The fourth and subsequent octets contain codings as follows: If bit 8 of the octet is set to zero, the remaining 7 bits of the octet contain a GSM Default Alphabet character, whereas if bit 8 of the octet is set to one, then the remaining seven bits are an offset value added to the 16 bit base pointer defined earlier... 3)  If the first octet of the alpha string is set to '82', then the second octet contains a value indicating the number of characters in the string, and the third and fourth octets contain a 16 bit number which defines the complete 16 bit base pointer to a "half page" in the UCS2 code space...