In this case, I would use a loop instead of multiplication. Something like that:
int newX = X; int poweredB = ( 1 << B ); // 2^B for( int i = 0; i < poweredB ; ++i ) { newX += Y; // or change X directly, if you will not need it later. } int result = ( 1 << A ) * newX;
But note : for some situations this will work - only if you have a guarantee , this result will not be overwhelmed. In your case, when Y is big positive and X is a big negative number (βbigβ is argh, this is too subjective), this will definitely work. But if X is big positive and Y is big positive, there will again be overflow. And not only in this case, but also with many others.
source share