Bitshift to the left, this multiplies the numbers by 2 for each space shift, in the same way that moving the decimal numbers to the left multiplies them by 10.
Use the << operator, for example:
int twoPowZero = 1; // any number^0 is 1 int twoPowOne = 1 << 1; // this sets the '2' bit to '1' int twoPowTwo = 1 << 2; int twoPowFive = 1 << 5; int twoPowTen = 1 << 10;
etc. until you reach 1 << 30 . If you use a signed 32-bit integer, then 1 << 31 will give you -2147483648 due to two additions. If you want to go higher than using long long unsigned int or uint64_t (64-bit integer). Or, if your platform supports it: uint128_t .
If you want to go even higher, you will need to collapse your own Big Whole code. Note that some platforms and compilers have a 128-bit integer type, but execution performance varies: they may require a processor that can perform 128-bit operations, or they can split it into two 64-bit operations.
source share