[JavaScript] Easy to understand - bit manipulation
The main process is traversal each bit of a | b and c to sum the cost.\n\nIf the bit of a | b equals to the same bit of c, then we don\'t need to flip it.\nIf t
The main process is traversal each bit of `a | b` and `c` to sum the cost.\n\nIf the bit of `a | b` equals to the same bit of `c`, then we don\'t need to flip it.\nIf they are not same, we could find the logic of solving from this table easily:\n\na | b | c | cost\n- | - | - | -\n0 | 0 | 1 | 1\n1 | 0 | 0 | 1\n0 | 1 | 0 | 1\n1 | 1 | 0 | 2\n\nSo, here\'s the code:\n\n```js\nconst minFlips = (a, b, c) => {\n  let ret = 0;\n  while (a > 0 || b > 0 || c > 0) {\n    if (((a & 1) | (b & 1)) !== (c & 1)) {\n      ret += (a & 1) === 1 && (b & 1) === 1 ? 2 : 1;\n    }\n    a >>>= 1;\n    b >>>= 1;\n    c >>>= 1;\n  }\n  return ret;\n};\n```\n\nSince the `a`, `b` and `c` are all int, we could set the traversal times and calculate with a mask. The code could be like this:\n\n```js\nconst minFlips = (a, b, c) => {\n  let ret = 0;\n  let mask = 1;\n  for (let i = 1; i < 32; ++i) {\n    if (((a & mask) | (b & mask)) !== (c & mask)) {\n      ret += (a & mask) === mask && (b & mask) === mask ? 2 : 1;\n    }\n    mask <<= 1;\n  }\n  return ret;\n};\n```
['JavaScript']