|
-
February 17th, 2012, 03:37 PM
#16
Re: shifting a 32bit in a array!!!!
 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...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
February 17th, 2012, 04:48 PM
#17
Re: shifting a 32bit in a array!!!!
 Originally Posted by VladimirF
So what are you shifting? Elements in array or their content?
I want to shift elements in the array!!!!!
-
February 17th, 2012, 04:58 PM
#18
Re: shifting a 32bit in a array!!!!
 Originally Posted by hemanth144
I want to shift elements in the array!!!!!
You were already pointed out that
 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?
Victor Nijegorodov
-
February 17th, 2012, 05:31 PM
#19
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.
Last edited by hemanth144; February 18th, 2012 at 02:58 AM.
-
February 17th, 2012, 09:05 PM
#20
Re: shifting a 32bit in a array!!!!
 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
February 18th, 2012, 02:32 AM
#21
Re: shifting a 32bit in a array!!!!
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?
Last edited by Igor Vartanov; February 18th, 2012 at 02:34 AM.
Best regards,
Igor
-
February 18th, 2012, 05:43 AM
#22
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...
-
February 21st, 2012, 09:35 AM
#23
Re: shifting a 32bit in a array!!!!
 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...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 21st, 2012, 09:43 AM
#24
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.
Last edited by ahoodin; February 21st, 2012 at 11:48 AM.
ahoodin
To keep the plot moving, that's why.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|