private static final byte[]
   encode3to4(final byte[] src, final int sOffset, final int numBytes,
              final byte[] dest, final int dOffset) {
      //           1         2         3
      // 01234567890123456789012345678901 Bit position
      // --------000000001111111122222222 Array position from threeBytes
      // --------|    ||    ||    ||    | Six bit groups to index ALPHABET
      //          >>18  >>12  >> 6  >> 0  Right shift necessary
      //                0x3F  0x3F  0x3F  Additional AND

      // Create buffer with zero-padding if there are only one or two
      // significant bytes passed in the array.
      // We have to shift left 24 in order to flush out the 1's that appear
      // when Java treats a value as negative that is cast from a byte to an int.
      final int inBuff =
            (  numBytes > 0 ? ((src[sOffset    ] << 24) >>>  8) : 0)
            | (numBytes > 1 ? ((src[sOffset + 1] << 24) >>> 16) : 0)
            | (numBytes > 2 ? ((src[sOffset + 2] << 24) >>> 24) : 0);
      switch (numBytes) {
      case 3:
         dest[dOffset    ] = ALPHABET[(inBuff >>> 18)       ];
         dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
         dest[dOffset + 2] = ALPHABET[(inBuff >>>  6) & 0x3F];
         dest[dOffset + 3] = ALPHABET[(inBuff       ) & 0x3F];
         break;
      case 2:
         dest[dOffset    ] = ALPHABET[(inBuff >>> 18)       ];
         dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
         dest[dOffset + 2] = ALPHABET[(inBuff >>>  6) & 0x3F];
         dest[dOffset + 3] = EQUALS_SIGN;
         break;
      case 1:
         dest[dOffset    ] = ALPHABET[(inBuff >>> 18)       ];
         dest[dOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3F];
         dest[dOffset + 2] = EQUALS_SIGN;
         dest[dOffset + 3] = EQUALS_SIGN;
         break;
      }
      return dest;
   }