Re: Algorithm question - binary matrix

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thank you Tim

it works great !



This is the same bit shifting solution I made but a lot shorter

Thank you



sharon





ps

you saved me 50 $ from gorbachev there .

;)





"Tim Roberts" <timr@xxxxxxxxx> wrote in message
news:j0lk41t4qsee4bge8sktgfsi0pqo0g6cp5@xxxxxxxxxx
> "Sharon" <Sharon669@xxxxxxxxxxx> wrote:
>>
>>Hi all
>>
>>I know this is not algorithm newsgroup ... but I think you will find this
>>interesting
>>
>>I have matrix 2x4 or 3x8 or 4x16.....
>>
>>I want to fill the matrix with the base 2 sequence numbers
>>
>>And using 2 for loops and one line using the indexes i , j to fill the
>>matrix
>>
>>For(int i=0;i<COL;i++)
>> for(int j=0;j<ROW;j++)
>> Matrix[i][j] = ??????;
>
> Matrix[i][j] = !!(i & (1 << j));
>
> Or:
>
> for( int i = 0; i < COL; i++ )
> {
> int ii = i;
> for( int j = 0; j < ROW; j++, ii>>=1 )
> Matrix[i][j] = ii & 1;
> }
> --
> - Tim Roberts, timr@xxxxxxxxx
> Providenza & Boekelheide, Inc


.