How can I read 40 bits of data from a heap at a time.
I think we need more information to understand what you are trying to do.
In C, if p is a pointer to the heap, then this will read 40 bits (5 bytes) starting at address p:
memcpy(dst, p, sizeof(dst));
Does that do what you want?