This is a discussion on hadamard matrix within the C++ Programming forums, part of the General Programming Boards category; Hi What would the best method be to create a Hadamard matrix in C++? 0: 11111111111111111111111111111111 1: 11111111111111110000000000000000 2: 11111111000000000000000011111111 ...

Hi

What would the best method be to create a Hadamard matrix in C++?

0: 11111111111111111111111111111111
1: 11111111111111110000000000000000
2: 11111111000000000000000011111111
3: 11111111000000001111111100000000
4: 11110000000011111111000000001111
5: 11110000000011110000111111110000
6: 11110000111100000000111100001111
7: 11110000111100001111000011110000
8: 11000011110000111100001111000011
9: 11000011110000110011110000111100
10: 11000011001111000011110011000011
11: 11000011001111001100001100111100
12: 11001100001100111100110000110011
13: 11001100001100110011001111001100
14: 11001100110011000011001100110011
15: 11001100110011001100110011001100

I'd like to store the matrix in a 2 dimensional array with dimensions 16 x 32.

Is this correct so far..?

Code:
```int f, N, had[16][32];
for (f=0; f<16; f++);
for (N=0; N<32; N++);

So i'm now looking to fill the array with the hadamard values and I don't know how to do this. Any help would be very much appreciated.

det

2. Are you having problems actually computing the hadamard matrix values? Or the coding behind it? Since you say you have a 16x32 matrix with only 2 values ( usually -1 and 1's but 0's and 1's is fine ), you can do a trick.

Just have an array of 16 integers and let the integer bits (assuming an integer is 4 bytes on your system ) stand for the rows. So if you decalred:

Code:
`int Matrix[16];`
then you are subscripting into the rows and then you can use bitwise manipulation to check individual bits. You could wrap this nicely in a class and save on storage. If storage isn't a primary concern to you then feel free to declare the 2D array.

3. One solution is dynamic allocation.

Kuphryn

4. thanks for the replies. Thanks for the pointer MrWizard that's just what i was looking for.