**@Alvaro**:

You need to be much more precise than that. In your description of the problem you speak of "matrices" B, i and j, which are nowhere to be found in your code. You also don't explain what you mean by "matrix", because the conventional definition doesn't match either.

Once we have a precise statement of the problem, hopefully with some examples, I am pretty sure I'll be able to write some basic code to do what you need.

You're right. However, if I wanted to paste the whole code It would require about 10k lines of code at the moment, so I decided to strip it a little. And my question considers only:

** How to rewrite one integer to another BIT BY BIT**. That is the part I am stuck at. I just have no idea how to write an instruction that does this:

**if the i-th bit in integer x is set, that set a j-th bit in integer y, if the i-th bit in x is unset, unset j-th bit in y.** Also notice, that used integers are template parameters/arguments so no constant values should be used, rather constructors like CONTAINER_INT(1) or CONTAINER_INT(0).

Hope this clears the problem.

PS.: And I want to do it bit by bit. I just want to avoid if statement.

EDIT: After giving it some thought, I paste the whole function (only the line with if statement has to be changed):

template <class INT_TYPE,class CONTAINER_INT>
inline void BitsetChooseSerial(CONTAINER_INT *From,INT_TYPE FromRows,INT_TYPE *WhichRows,INT_TYPE NRows,INT_TYPE *WhichCols,INT_TYPE NCols, CONTAINER_INT *To)
{
//ToRows==NRows
static const INT_TYPE ContainerSize=sizeof(CONTAINER_INT)*8;
INT_TYPE ElementIndex,C,i,t,tC;
for (INT_TYPE j=0;j<NCols;j++)
{
C=WhichCols[j]*FromRows;
tC=j*NRows;
for (i=0;i<NRows;i++)
{
ElementIndex=WhichRows[i]+C;
t=i+tC;
if (From[ElementIndex/ContainerSize] & (CONTAINER_INT(1) << (ElementIndex%ContainerSize))) To[t/ContainerSize] |= CONTAINER_INT(1) << (t%ContainerSize); //change this to direct bit shift
}
}
}

**Edited by Misery, 17 October 2012 - 01:36 AM.**