hi all,
i am new to programming,

my problem is that after certain data manipulation i will a array which will have only zeros & ones. (example x[5]={0,0,1,0,1}

now i would like to store the contents of the array in another variable like A(say)=00101.
but the codes which i written saves it as A=101.

code which wrote is
//

``````p=0;
A=0;
for(i=0;i<=4;i++)
{
for(s=i;s<=5;s++)
{
p=10*p;
}

A=A+(m[i]*p);
p=1;
}``````

//
thank u

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by bobraj

hi all,
i am new to programming & to this site,

plz let me clarify the problem further.

my problem is that after certain data manipulation (in a function) i will a array which will have only zeros & ones & twos. (example x[10]={0,0,1,0,1,2,2,2,2,2},x[10]={1,0,1,2,2,2,2,2,2,2},x[10]={0,0,0,1,1,1,0,0,2,2} etc...)

now i would like to store the contents of the array in another variable like A(say)=00101, A=101,A=00011100.
(ignoring all 2s but keeping all preceding 0s. 2s represent junk values )
but the codes which i written saves it as A=101,A=101,A=11100.

code which i wrote is
//

``````int i,j,t,s;
int A,p;

for(i=0;i<10;i++)
{
t=0;
A=0;
while(x[i]!=2)
{
t++;
}

p=1;
for(j=0;j<=t;j++)
{
for(s=t;s>=(t-j);s--)
{
p=10*p;
}

A=A+(m[j]*p);
p=1;
}

}``````

//
thank u

May I suggest you use the digits 1, 2 & 3, instead of 0, 1, & 2?

Because you can't "make" a number which begins with 0's: 01, 001, 02, 002, etc., are not a number. Anything beginning with a real number, would be fine though: 101, 20, 103, etc.

Other idea's would include using bit values within the bytes, but that sounds unnecessarily difficult for a beginner, and keeping the values in an integer array, where the zero's would be fine.

Always put your code between code tags on any forum.

May I suggest you use the digits 1, 2 & 3, instead of 0, 1, & 2?

Because you can't "make" a number which begins with 0's: 01, 001, 02, 002, etc., are not a number. Anything beginning with a real number, would be fine though: 101, 20, 103, etc.

Other idea's would include using bit values within the bytes, but that sounds unnecessarily difficult for a beginner, and keeping the values in an integer array, where the zero's would be fine.

Always put your code between code tags on any forum.

thanks for helping. solved the problem:)