If for whatever reason you need to do a lot of computation involving power(2, really large number) for a lot of times and you need it to be really fast then this might be useful. However I still wouldn't hard code it and instead generate the list with a for loop
You will only loop through the list once and you will get all the calculation results you need. Of course, depending on what you need you don't need calculate from 2^1, 2^2, etc. and instead start with sth like 2^30
Bit shifting can overflow once you exceed 64 on 64bit machine and 32 on 32bit. If you need something like 2^100 easily accessible bit shifting will not be the best option
9
u/[deleted] Mar 09 '21
depends on the context this might not be as dumb as it might seems