static int calculateBCHCode ( int value , int poly ) { if ( poly == 0 ) { throw new IllegalArgumentException ( "0 polynomial" ) ; } // If poly is "1 1111 0010 0101" (version info poly), msbSetInPoly is 13. We'll subtract 1 // from 13 to make it 12. int msbSetInPoly = findMSBSet ( poly ) ; value <<= msbSetInPoly - 1 ; // Do the division business using exclusive-or operations. while ( findMSBSet ( value ) >= msbSetInPoly ) { value ^= poly << ( findMSBSet ( value ) - msbSetInPoly ) ; } // Now the "value" is the remainder (i.e. the BCH code) return value ; }
operations . We don t care if coefficients are positive or negative .