This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

shifting arrays

hi,

i'm using uVision3.33 , uC-80c31x2.
my question is:
I'v initilize buffer array which is been loaded with 24 Byte each interval time.
now i want to shift the all array right/left by 1 bit.
maybe an example will clarify bettet:

unsigned char array_1[24];
unsigned char array_1[24] = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24};


the array's values in the example are just for example.
probably the operand '>>' must be use.
the result i wish for is:
(shifting all the array right only one time)

unsigned char array_1[24] = {
0x00,0x81,0x01,0x82,0x02,.....,0x92};


thanks in advance.

Parents
  • So what you want is a sort of 'shift with carry.' Looks easy enough:

    array[24] >>= 1;
    array[24] |= (array[23] << 7);
    array[23] >>= 1;
    array[23] |= (array[22] << 7);
    


    and so on. Feel free to make a for loop out of it.
    If you care about speed or code size, you should implement this in assembly using the RRC instruction.

    Regards,
    - mike

Reply
  • So what you want is a sort of 'shift with carry.' Looks easy enough:

    array[24] >>= 1;
    array[24] |= (array[23] << 7);
    array[23] >>= 1;
    array[23] |= (array[22] << 7);
    


    and so on. Feel free to make a for loop out of it.
    If you care about speed or code size, you should implement this in assembly using the RRC instruction.

    Regards,
    - mike

Children
No data