private static byte divmod ( byte [ ] number , int firstDigit , int base , int divisor ) { // this is just long division which accounts for the base of the input digits int remainder = 0 ; for ( int i = firstDigit ; i < number . length ; i ++ ) { int digit = ( int ) number [ i ] & 0xFF ; int temp = remainder * base + digit ; number [ i ] = ( byte ) ( temp / divisor ) ; remainder = temp % divisor ; } return ( byte ) remainder ; }
Divides a number represented as an array of bytes each containing a single digit in the specified base by the given divisor . The given number is modified in - place to contain the quotient and the return value is the remainder .