Velocity Reviews > Using Binary numbers to create a matrix

# Using Binary numbers to create a matrix

Kaytiana
Junior Member
Join Date: Mar 2010
Posts: 1

 03-20-2010
Hello,

OK, so I am new to this whole C programming thing and, quite frankly, it confuses the hell outta me! So I am hoping someone could help me out, with pretty detailed instructions explaining what each command does!

Please bear with me as I may not be very clear when I explain this, or concise!

I want to create a matrix as follows;

The matrix will be of size NxN, where N=2^n and n is the length of the binary numbers we use.

So the matrix will be M[i,j] where i,j = 0,...,N-1, and i,j correspond to the n-bit binary representations of that number.

if i =/= j then the M[i,j] entry will be determined by
if (the binary form) of j has a 0 in as its first digit and i is differs to j ONLY by having a 1 as its first digit then the entry M[i,j] = alpha
if j has a 1 as its final (nth) digit and i differs to j ONLY by having a 0 as its final digit then M[i,j] = beta
if j has a 10 within its binary representation and i differs ONLY by having these two digits switched to 01 then M[i,j] = lambda
otherwise M[i,j] = 0

And if i = j then M[i,i] = -sum_{j} M[i,j]

so, for example, if n=3 we have an 8x8 matrix,
if j = 1 = 001 and i = 5 = 101 then M[5,1] = alpha
if j = 1 = 001 and i = 0 = 000 then M[0,1] = beta
if j = 2 = 010 and i = 1 = 001 then M[1,2] = lambda
if j = 3 = 011 and i = 5 = 101 then M[5,1] = 0

I am not sure if this makes sense, but if anyone knows how I could construct this it would be a huge help! Thanks.