Unexpected behaviour with pow(2,x) in Embedded C
While this is a programming question, it is one that can turn up quite often in embedded settings, so it's not really off-topic here.

The most likely issue is indeed caused by truncation (not rounding - that does not happen).

A far better approach would be to use a bit shift operator - this will not only be more true to your intent, but faster too, as in basic circumstances it is a primitive operation directly implemented in many ALUs (though not, as pipe points out, the AVR, which can only shift one bit position at a time)

int j = 2;

PORTJ = (1 &lt;&lt; j) - 1


(EDIT - thanks to ilkkachu for the correction)

You will find such operations all over the place in I/O macros for many microcontrollers and hardware or bitfield related code on larger systems.

(Incidentally, should you every try to use this to shift or produce a value larger than an int, look up the type rules which apply - they are not necessarily intuitive!)