97e9dd4bb8961bf6c2bb3e7d0b599878d6f83424ac858e4dad50b35cb87680b2.json raw

   1  {"ast":null,"code":"const Utils = require('./utils');\nconst G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;\nconst G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;\nconst G15_BCH = Utils.getBCHDigit(G15);\n\n/**\n * Returns format information with relative error correction bits\n *\n * The format information is a 15-bit sequence containing 5 data bits,\n * with 10 error correction bits calculated using the (15, 5) BCH code.\n *\n * @param  {Number} errorCorrectionLevel Error correction level\n * @param  {Number} mask                 Mask pattern\n * @return {Number}                      Encoded format information bits\n */\nexports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {\n  const data = errorCorrectionLevel.bit << 3 | mask;\n  let d = data << 10;\n  while (Utils.getBCHDigit(d) - G15_BCH >= 0) {\n    d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;\n  }\n\n  // xor final data with mask pattern in order to ensure that\n  // no combination of Error Correction Level and data mask pattern\n  // will result in an all-zero data string\n  return (data << 10 | d) ^ G15_MASK;\n};","map":null,"metadata":{},"sourceType":"script","externalDependencies":[]}