works for powers of 2