Are there features in programming languages that allow you to directly access the $k^{th}$ bit of a number. Treating it like an integer.I'm not talking of using bit shifting to retrieve a number. But directly access the bit at index $i$ of a number as if it were an array.I'm looking at this feature to replace shifting to write an algorithm I was working on. If it isn't faster than shifting, then such a feature would be pointless.I didn't ask this on stack overflow as this isn't about a specific programming language, but about whether programming languages in general have this feature.Also are there language features for inverting the bits(a specific bit or as many as needed) of a number?
Bit operations; Treating a number like an array
programming languages
The answer depends on the programming language and, to some extent, on the CPU. For any practical purpose, though, extracting the $k$th bit is an $O(1)$ operation even on a big integer stored on several machine words, since in order to extract the $k$th bit, you can use the following algorithm:Determine which word the $k$th bit is in, and which bit in the word.Extract the appropriate bit from the appropriate word.In practice it is a reasonable assumption to make that indices of bits fit into a machine word, and so all of these operations are $O(1)$.