javascript solutions
\n/////////////////////////////// Solution 1 //////////////////////////////////\n// 1260ms\nconst mod = BigInt(1e9 + 7);\nconst concatenatedBinary = (n) => {\n 
```\n/////////////////////////////// Solution 1 //////////////////////////////////\n// 1260ms\nconst mod = BigInt(1e9 + 7);\nconst concatenatedBinary = (n) => {\n    let res = 0n;\n    let shift = 1n;\n    for (let i = 1n; i <= n; i++) {\n        if (i == (1n << shift)) shift++;\n        res <<= shift;\n        res += i;\n        res %= mod;\n    }\n    return Number(res);\n};\n\n// 664ms\nconst MOD = 1e9 + 7;\nconst concatenatedBinary = (n) => {\n    let res = 0;\n    let shift = 1;\n    for (let i = 1; i <= n; i++) {\n        if (i == (1 << shift)) shift++;\n        res *= (2 ** shift); // difference, don\'t know what the hack: res << shift cause Number overflow while res * (2 ** shift) not, both should work the same\n        res += i;\n        res %= MOD;\n    }\n    return res;\n};\n\n\n/////////////////////////////// Solution 2 //////////////////////////////////\n// reference: https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/discuss/961350/C%2B%2B-O(N)-time-iterative\n// 1396ms\nconst mod = BigInt(1e9 + 7);\nconst concatenatedBinary = (n) => {\n    let res = 0n;\n    for (let i = 1n, shift = 0n; i <= n; i++) {\n        let singleBit = (i & (i - 1n)) == 0n;\n        if (singleBit) shift++;\n        res <<= shift;\n        res += i;\n        res %= mod;\n    }\n    return Number(res);\n};\n\n// 672ms\nconst MOD = 1e9 + 7;\nconst concatenatedBinary = (n) => {\n    let res = 0;\n    for (let i = 1, shift = 0; i <= n; i++) {\n        let singleBit = (i & (i - 1)) == 0;\n        if (singleBit) shift++;\n        res *= (2 ** shift); // difference\n        res += i;\n        res %= MOD;\n    }\n    return res;\n};\n\n/////////////////////////////// Solution 3 //////////////////////////////////\n// 2400ms\nconst mod = 1e9 + 7;\nconst concatenatedBinary = (n) => {\n    let res = 0;\n    for (let i = 1; i <= n; i++) {\n        let bin = i.toString(2);\n        let shift = bin.length;\n        res *= (2 ** shift);\n        res += i;\n        res %= mod;\n    }\n    return res;\n};\n\n/////////////////////////////// Solution 4 //////////////////////////////////\n// 180ms\nconst mod = 1e9 + 7;\nconst concatenatedBinary = (n) => {\n    let t = 2;\n    let res = 0;\n    for (let i = 1; i <= n; i++) {\n        if (i == t) {\n            t *= 2;\n        }\n        res = res * t + i;\n        res %= mod;\n    }\n    return res;\n};\n```
[]