private static void emitDigit ( int value , byte [ ] dst , int dstOffset , int xorMask ) { // The first byte is computed as ((value / 192) + 32) and the second // byte is computed as ((value % 192) + 32). To speed things up a bit, // the integer division and remainder operations are replaced with a // scaled multiplication. // approximate value / 192 int a = ( value * 21845 ) >> 22 ; // approximate value % 192 // Note: the value 192 was chosen as a divisor because a multiply by // 192 can be replaced with two summed shifts. int b = value - ( ( a << 7 ) + ( a << 6 ) ) ; if ( b == 192 ) { // Fix error. a ++ ; b = 0 ; } dst [ dstOffset ++ ] = ( byte ) ( ( a + 32 ) ^ xorMask ) ; dst [ dstOffset ] = ( byte ) ( ( b + 32 ) ^ xorMask ) ; }
Emits a base - 32768 digit using exactly two bytes . The first byte is in the range 32 .. 202 and the second byte is in the range 32 .. 223 .