Re: shifting a 32bit in a array!!!!
Quote:
Originally Posted by
S_M_A
Frankly, why is it so impossible to spend a few minutes to write a question that clearly states the issue?
Assuming that you want to shift
int p[32]={1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0} from left to right this should do it
Code:
for(int i=1;i<31;i++)
{
p[i]=p[i-1];
}
p[31] = 0;
Not perhaps rather something like:
Code:
for(int i = 31; i > 0; i--)
{
p[i]=p[i-1];
}
p[0] = 0;
? ;)
Based on the assumption, of course, that "left" means the end with the lower index, i.e. 0, just like it's written in the initializer.
Now I just hope you didn't just want to give the OP something to debug and now I've spoiled it... ;)
Re: shifting a 32bit in a array!!!!
Quote:
Originally Posted by
VladimirF
So what are you shifting? Elements in array or their content?
I want to shift elements in the array!!!!!
Re: shifting a 32bit in a array!!!!
Quote:
Originally Posted by
hemanth144
I want to shift elements in the array!!!!!
You were already pointed out that
Quote:
Originally Posted by
GCDEF
Exclamation points don't add clarity to your post, no matter how many you use. Since nobody understood your question the first time, try rewording it.
So how did you try it and what went wrong?
Re: shifting a 32bit in a array!!!!
I written a code like this. This code is for linear feedback shift register for 32bit length.
#include <iostream>
#include<bitset>
#include<string>
#define lfsr_ length=32;
using namespace std;
class lfsr
{
public:
void computation()
{
int p[33]={0,0,1,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,1,0,0,1,0,1,0,1,0,1,1,0,1,0,0};
int n1,n2,n3;
n1= p[32] ^ p[28];
n2= n1 ^ p[27];
n3= n2 ^ p[1];
p[0]=n3;
// this is the code for shifting which i written.could anyone tell me if i write code like below, the elements of array shifts properly.
int i;
for(i=32; i>1; i--)
{
p[i]=p[i-1];
cout<<p[i];
}
}
};
int main()
{
lfsr l1;
l1.computation();
return 0;
}
shift elements in the array contains some elements like{0,1,1,......} and this element has to shift from left to right.
its not showing any error but having a doubt whether it shifts properly if I write a code like above.
Re: shifting a 32bit in a array!!!!
Quote:
Originally Posted by
hemanth144
I want to shift elements in the array!!!!!
Please explain EXACTLY what you mean by "shift elements in the array"!!!!!!!!!!!!!! Try do to it without using the phrase "shift elements in the array"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Try to do it without exclamation points. They are considered rude!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Re: shifting a 32bit in a array!!!!
Quote:
its not showing any error but having a doubt whether it shifts properly if i write a code like above.
To make your doubt to vanish you have to understand first what "shift properly" really means, and analyze your code whether it does what's required. And even if we can help with 'analyze' part, the 'understand' part is all yours. In fact, this is what we say here from the very beginning. If you're not able to understand your assignment, how else could we help?
Re: shifting a 32bit in a array!!!!
No you didn't spoil anything Eri523. I was just to tired. Posting on a friday evening after a dinner with wine isn't to be recommended either... :o
Re: shifting a 32bit in a array!!!!
Quote:
Originally Posted by
hemanth144
I written a code like this. This code is for linear feedback shift register for 32bit length.
What does Linear feedback shift register have to do with shifting elements in your array?
You can't really start solving the problem until you understand what the problem is...
Re: shifting a 32bit in a array!!!!
1) ON MS by default an integer is a 32 bit variable.
2) What you have is an 32 item array of 32 bit variables, and you are using only bit0 in each of them.
So you are effectively using an array of 32 bits as a single bit.
You can probably do this assignment in a more elegant fashion with bit operations and an 32 bit unsigned integer.