I just want to know that is there any way to shift array elements using bitwise operator. Maybe with overloading the bitwise operator.
You probably mean to do something like
int array[] {1, 2, 3};
array << 1; // -> array should become 2, 3, 1
This is not possible. For operator overloading one of the operands must be of class type, but neither array, nor 1 are classes. You can overload this operator for containers like std::array or std::vector of course.
template<typename T, size_t N>
void operator<<(std::array<T, N> &arr, int n) {
// shift things around, the implementation is up to you ;)
}
void foo() {
std::array<int, 3> array {1, 2, 3};
array << 1; // -> array becomes 2, 3, 1
}
Even if it is possible why we are not using this method while bitwise operator are the faster compare to arithmetic operators?
Not sure what you mean here. Overloading a bit-shift-operator (or any operator for that matter) doesn't do any actualy bit shifting, it's just a fancy way to call some function.
myArray[5] >>= 1would shift the sixth element ofmyArrayright by one bit. Is that all you're asking? Please clarify.