C++ | Easy to Understand with explanation
\nclass Solution {\npublic:\n\t// get number of bits in a number\n    int getBinary(int n) {\n        int count = 0;\n        while(n > 0) {\n            n = n 
```\nclass Solution {\npublic:\n\t// get number of bits in a number\n    int getBinary(int n) {\n        int count = 0;\n        while(n > 0) {\n            n = n / 2;\n            count++;\n        }\n        return count;\n    }\n    int concatenatedBinary(int n) {\n        long long ans = 1;\n        int mod = 1e9 + 7;\n        for(int i = 2; i <= n; i++) {\n            int  bits = getBinary(i);  // number of bits in i\n            ans = ((ans << bits) % mod + i) % mod; // left shift the answer by number of bits and add current element into it\n        }\n        return (int)ans;\n    }\n};\n```
[]