C++ one line solution | Explained arithmetically
Deduction\nIt is impossible to find an answer for even numbers since the bitwise or of two consecutive number is always odd \ni.e.:\n    \u274C $6 (0b110)$\n>  
# Deduction\nIt is impossible to find an answer for even numbers since the bitwise or of two consecutive number is always odd \ni.e.:\n    \u274C $6 (0b110)$\n>   $4 |_{or} 5 = 5$\n>   $5 |_{or} 6 = 7$\n>   $6 |_{or} 7 = 7$\n     \n   \u274C $2 (0b10)$ \n>  $0 |_{or} 1 = 1$\n>  $1 |_{or} 2 = 3$\n\nBut since all primes expect 2 are odd we just need to exclude 2 from the algorithm.\n\n---\n\nIf we observe any number ```a``` formed by a sequence of **consecutive** set bit\n$a=2^0+2^1+\\dots+2^{n-1}=\\sum_{i=0}^{n-1} 2^i = 2^n - 1$,\nwe note that the minimum value ```b``` for which $a=b|_{or}(b+1)$\nis the number we obtain by clearing the most significative bit from ```a``` ($2^{n-1}$),\n$b=a-2^{n-1}=2^0+2^1+\\dots+2^{n-2}=\\sum_{i=0}^{n-2} 2^i = 2^{n-1} - 1$,\nsince $b+1 = 2^{n-1}$ represents the bit we removed from ```a``` to obtain ```b```\n$b|_{or}(b+1) = (2^{n-1}-1)|_{or}2^{n-1} = 2^{n-1} + 2^{n-1} - 1 = 2^{n}-1 = a$\ni.e. \n>   for $n=3 $\n>   $ a = 2^n-1 = 7 (0b\\underline111)$\n>   $b = 2^{n-1}-1 = 3 (0b\\underline011)$\n>   $b|_{or}(b+1) = 0b011 |_{or} 0b100 = 7 (0b111) = a$\n\nThis process can be extended to any odd number,\nsince odd numbers can be decomposed into their less significative consecutive bit sequence plus a constant.\n$a = 2*k+1 = \\alpha*2^{n+1} + \\sum_{i=0}^{n-1} 2^i = \\alpha*2^{n+1} + 2^{n}-1 = \\beta + 2^n-1$ for some $\\alpha, n$,\nthen\n$b = \\beta + \\sum_{i=0}^{n-2} 2^i = \\beta + 2^{n-1}-1$\n$b+1 = \\beta + 2^{n-1}$\n$b|_{or}(b+1) = (\\beta + 2^{n-1}-1) |_{or} (\\beta + 2^{n-1}) = (\\beta|\\beta) + [(2^{n-1}-1) |_{or} 2^{n-1}] = \\beta +2^n-1 = a$\ni.e.\n$ a = 13 = 8 + 4 + \\underline{1}$\n> $\\beta = 8 + 4$, $n = 1  $\n> then $ b = \\beta + 2^{n-1}-1 = (8+4) + 2^{1-1}-1 = 12$\n> $12|_{or}13 = 13 $\n\n$ a = 11 = 8 + \\underline{2 + 1}$\n> $\\beta = 8,$ $n = 2$\n> then $ b = \\beta + 2^{n-1}-1 = 8 + 2^{2-1}-1 = 9$\n> $9|_{or}10 = 11 $\n---\n\nIt follows that for each odd numbers the answer is to set to 0 the bit at the previous index of the lowest clear bit\ni.e.: \n\u2714\uFE0F $13 (0b1101)$\n> the lowest clear bit is at index **1** $0b11\\underline{0}1$,\n> reset at index **0** $0b110\\underline{1}$ ->$12 (0b1100)$\n> $12 |_{or} 13 = 13$\n\n\u2714\uFE0F $11 (0b1011)$ \n> the lowest clear bit is at index **2** $0b1\\underline{0}11$\n> reset at index **1** $0b10\\underline{1}1$ -> $9(0b1001)$\n> $9 |_{or} 10 = 11$\n---\n# Algorithm\n\nTo extract the lowest clear bit the simplest way is to use the [asm instruction **blci**](https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set#TBM_(Trailing_Bit_Manipulation)) that can be written as ```x | ~(x+1)``` or ```x | -(x+2)```\ni.e.:\n> **bin**$(183) = 0b[0\\dots]10110111$\n> **blci**$(0b[0\\dots]10110111) = 0b[1\\dots]11110111$\n\nThe **blci** instruction will return a mask that has all bit set except the lowest 0.\n\nThen by shifting arithmetically right by 1 (**sar**) the mask will move with the clear bit set to the previous (the one we need to clear as previously stated).\n(N.B.we work with integer so the most significative bit is always 0 if positive, hence the logical shift is equivalent to the arithmetic in this case) \n> **sar**$(0b[1\\dots]11110111) = 0b[1\\dots]11111011 $\n\nThis will lead to the mask we need to apply to the original number to obtain the result\n> $0b[0\\dots]10110111$ **&** $0b[1\\dots]11111011 = 0b[0\\dots]10110011 $\n---\n# Code\n```cpp []\n// map(x:nums) -> get lowest clear bit from x, reset previous bit from x\n// if x>2 and trailing bit manipulation is supported,\n// the generated asm should look like:\n//     blci eax, edi // r = x | ~(x+1)\n//     sar  eax      // r >>= 1\n//     and  eax, edi // r &= x\n//     ret\n// if not supported:\n//     mov eax, -2  // r = -2\n//     sub eax, edi // r -= x\n//     or  eax, edi // r |= x\n//     sar eax      // r >>= 1\n//     and eax, edi // r &= x\n//     ret\n\n#pragma GCC target("bmi,tbm")\nclass Solution {\npublic:\n    vector<int> minBitwiseArray(vector<int>& nums) {\n        vector<int> ret(nums.size());\n        transform(nums.begin(), nums.end(), ret.begin(), [](int x){\n            return x > 2 ? x & ((x | ~(x+1)) >> 1): -1;\n        });\n        return ret;\n    }\n};\n```
['Bit Manipulation', 'C++']