hi everyone,i Have posted a code where i have created a structure in which i am defining bitfields.
If suppose for the object testvar[2][K] i wanna assign
{1,1,1},{1,0,1},should i assign them individually or can i assign at once like testvar[1][K].testa=7; //for {1,1,1}
testvar[2][k].testa=5;//for{1.0,1}
please help me,

#include<conio.h>
#include<string.h>
#include<iostream.h>

#define K 3
struct test
{
char testa:6;
char testb:10;
}

testvar[2][K];

int main()
{
//How do i assign value to the object testvar[2][K]???

getch();
return 0;    
}

Recommended Answers

All 7 Replies

Why are you using a multidimensional array?

If you explain a bit more stuff I might be able to help.

I am using 2 dimensional array coz i wan to take the polynomials for my convolutional encoder.
Depending on K value i will have to fix my polynomials.
If i take a matrix and assign values it may consume more memory so what i thought was to use bitfields and then assign the bits.
Is it not possible ??

Since I know nothing about bitfields I don't know what value to assign it but you can give it a value by going

#include <iostream>
#include <conio.h>

#define K 3

using namespace std;

int main()
{
	struct test
	{
		char testa:6;
		char textb:10;
	}testvar[2][K];
	//I put in 111 as the value but it just gives me some ascii character
	testvar[0][K].testa = 111;
	cout << testvar[0][K].testa << endl;
	
	getch();
	
	return 0;
}

/

Hi,
Thanks.But if i do as such,testvar[0][K]=111,then testvar[0][3] will be 111 since i have assigned K=3.
But i want testvar[0][1]=1;testvar[0][2]=1; like this by giving a decimal value to the varialbe.

I know what you wanna do but I don't know how to change numbers from say 7 to binary. If I knew how I could come up with a way to split it into the 3 columns. [0][0], [0][1], [0][2]

ok,Anyways thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.