OP wants unsigned long int
, then use that type in your macro
#define b(n) (1UL<<((unsigned)(n)))
When OP used (2 << (n))
, the result is type int
, as 2
is an int
. Operator <<
with an int
and unsigned
results in int
. Instead use unsigned
throughout.
Further, to emulate power(2,n)
, certainly the OP wanted to use 1
shifted left, rather than 2
shifted left.