1 var Utils = require('./utils')
3 var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)
4 var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)
5 var G15_BCH = Utils.getBCHDigit(G15)
8 * Returns format information with relative error correction bits
10 * The format information is a 15-bit sequence containing 5 data bits,
11 * with 10 error correction bits calculated using the (15, 5) BCH code.
13 * @param {Number} errorCorrectionLevel Error correction level
14 * @param {Number} mask Mask pattern
15 * @return {Number} Encoded format information bits
17 exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
18 var data = ((errorCorrectionLevel.bit << 3) | mask)
21 while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
22 d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))
25 // xor final data with mask pattern in order to ensure that
26 // no combination of Error Correction Level and data mask pattern
27 // will result in an all-zero data string
28 return ((data << 10) | d) ^ G15_MASK