Tuesday, 15 July 2014

c - 1 left shift by n -



c - 1 left shift by n -

in equation

#define mod 1000000007 int n; int num = ((1<<n)%mod)+2;

i have left shift 1 value of n , perform mod operation contain result within range of int. 1<<n not showing right value bigger values of n such 1000 or 10000. how ?

the maximum can left-shift 1 char_bit * sizeof(int) - 2. larger amount causes undefined behaviour.

if want work numbers 210000 going have utilize big integer library (or write own) , there no built-in info types can handle sort of number accurately.

another alternative utilize smarter algorithm modular exponentiation.

c bit-shift

No comments:

Post a Comment