[Java] Bit manipulation without any library function O(n) time, O(1) space
\n```\n\tpublic int concatenatedBinary(int n) {\n        int digits = 0, MOD = 1000000007;\n        long result = 0;\n        for(int i = 1; i <= n; i++){\n\t\t
\n```\n\tpublic int concatenatedBinary(int n) {\n        int digits = 0, MOD = 1000000007;\n        long result = 0;\n        for(int i = 1; i <= n; i++){\n\t\t\t/* if "i" is a power of 2, then we have one additional digit in\n\t\t\t   its the binary equivalent compared to that of i-1 */\n            if((i & (i - 1)) == 0) digits++; \n            result = ((result << digits) + i) % MOD;\n        }\n        \n        return (int) result;\n    }
[]