CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: shifting a 32bit in a array!!!!

    Quote Originally Posted by S_M_A View Post
    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.

  2. #17
    Join Date
    Feb 2012
    Posts
    18

    Re: shifting a 32bit in a array!!!!

    Quote Originally Posted by VladimirF View Post
    So what are you shifting? Elements in array or their content?


    I want to shift elements in the array!!!!!

  3. #18
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: shifting a 32bit in a array!!!!

    Quote Originally Posted by hemanth144 View Post
    I want to shift elements in the array!!!!!
    You were already pointed out that
    Quote Originally Posted by GCDEF View Post
    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

  4. #19
    Join Date
    Feb 2012
    Posts
    18

    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.

  5. #20
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: shifting a 32bit in a array!!!!

    Quote Originally Posted by hemanth144 View Post
    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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  6. #21
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    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

  7. #22
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    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...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  8. #23
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: shifting a 32bit in a array!!!!

    Quote Originally Posted by hemanth144 View Post
    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...

  9. #24
    Join Date
    Mar 2001
    Posts
    2,529

    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured