question: static public byte [ ] charArrayToHexArray ( char [ ] array ) { byte [ ] ascii = new byte [ ( array . length % 2 == 0 ) ? array . length : array . length + 1 ] ; for ( int i = 0 ; i < ascii . length ; i ++ ) { if ( i < ascii . length ) { if ( 'A' <= array [ i ] && array [ i ] <= 'F' ) { ascii [ i ] = ( byte ) ( array [ i ] - 'A' ) ; } else if ( 'a' <= array [ i ] && array [ i ] <= 'f' ) { ascii [ i ] = ( byte ) ( array [ i ] - 'a' ) ; } else if ( '0' <= array [ i ] && array [ i ] <= '9' ) { ascii [ i ] = ( byte ) ( array [ i ] - '0' ) ; } else { ascii [ i ] = 0x0 ; } } else { ascii [ i ] = 0x0 ; } } byte [ ] result = new byte [ array . length / 2 ] ; for ( int i = 0 ; i < result . length ; i ++ ) { result [ i ] = ( byte ) ( ( ascii [ i * 2 ] * 16 ) | ascii [ i * 2 + 1 ] ) ; } int i ; for ( i = result . length - 1 ; i >= 0 && result [ i ] == 0 ; i -- ) ; if ( i < result . length - 1 ) { result = Arrays . copyOf ( result , i + 1 ) ; } return result ; }
target:  Utility method that transforms a an ascii array representing hexa data in a real hexa array. The resulting array is half the size of the one passed as parameter.