Shifting a whole array sideways by one bit ( >>1)


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    96

    Default Shifting a whole array sideways by one bit ( >>1)

    I'm after a clue as to the least messy way to shift an array of 11 bytes by one bit right. Basically I have a situation where my program reads 88 bits of data from a pin into an array via a pulsin command. Every once in a while the first pulse of the 88 bits is missed, leaving 87 bits of good data offset by 1 bit. I know the missing (first) bit is always a logic 1, so I can add that back to the first read byte easily enough. The mess starts when I think of a way to ripple the one bit shift through the remaining 10 bytes, while transferring the high bit from one byte to the low bit of the next after the shift.

    Has anyone attempted this before and found a neater way of doing it ?

    So far I have this idea by using a shift on a two bytes at a time and keeping one of the bytes

    MyArray var byte[11]
    MyWord var word

    'load two sequential bytes off the end of the array into a word
    MyWord.lowbyte = MyArray[10] '10 is the 11th byte of the array
    MyWord.highbyte = MyArray[9]

    'shift the whole word by 1 bit
    MyWord = MyWord >> 1

    'copy the new last byte back to the array
    MyArray[10] = MyWord.lowbyte

    'then pull out byte 9 & 10 and repeat, then 8 & 9, etc, etc all the way back to bytes 0 & 1

    Messy. Anyone got another way, maybe manipulating the array more directly somehow ?

    Martin

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Shifting a whole array sideways by one bit ( >>1)

    How about
    Code:
    myArray VAR BYTE[11]
    Index VAR BYTE
    
    For Index = 0 to 87
      myArray.0[Index] = myArray.0[Index+1]
    NEXT
    /Henrik.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Shifting a whole array sideways by one bit ( >>1)

    If bits are 88 then I think we need 86 iterations in the loop and fill the last bit in the myArray by a 0.

    Ioannis

Similar Threads

  1. bit position variable
    By dsicon in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th December 2012, 21:41
  2. A little help with shifting out Arrays?
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 16th October 2012, 16:31
  3. shifting in decimals
    By lerameur in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th November 2011, 21:41
  4. Shifting bits
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd February 2011, 17:46
  5. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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