gajo wrote:

This is not linked to Delphi, but to programming in general. I've been
trying to write a table (matrice) of combinations of zeroes and ones. The
number of combinations is 2^n, so the matrix for n=2 would be
11
10
01
00


You could always just convert a series of integers to their binary equivalents. The conversion itself is simple enough to do - shifts and bit tests, packed bit arrays, whatever you prefer.

Actually, you don't even really need to store the results for this, if the matrix is always going to contain the full range from 0..2^max, unless you subsequently plan to use the matrix AS a matrix for some reason. Depending on the use you're putting it to you might find it simpler to use a simple expression to convert a matrix position (r,c) into an appropriate 1 or 0 value. Something like:

value := r & (1 SHL c);

...or whichever operator it is for a bitwise and. Alternatively:

value = (r shr c) & 1;

--
Message scanned by the Sheriff


_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to