View previous topic :: View next topic |
Author |
Message |
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
Shift Left a complete 128 bytes Array of 1 bit |
Posted: Sun Sep 16, 2018 2:53 am |
|
|
Hello to all!
I'm trying to shift left a 128 bytes Array of 1 or 2 bits!
Code: | unsigned int8 Array[128]; |
Of course, the MSB of Array[0] should become the LSB of array[1]..and so on
Can you open my eyes to the way to do that?
Thank you very much.
Wish you all the best!
Manu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sun Sep 16, 2018 3:17 am |
|
|
The compiler's shift_left function.
shift_left(Array,128,0);
Will shift all 128 bytes, propagating the bits from byte to byte as you describe (this will put '0' into the right hand bit). |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Sun Sep 16, 2018 3:53 am |
|
|
Many thanks!!! it's works like a charm.
I'm the happiest man because...since i tell to my wife that my work is finished for this Sunday morning....and we can go to the restaurant!!!,
Thanks again Ttelmah!
Wish you a great Sunday!
Manu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sun Sep 16, 2018 5:12 am |
|
|
That's a successful outcome!. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Sun Sep 16, 2018 11:46 pm |
|
|
Manu59114 wrote: | Many thanks!!! it's works like a charm.
I'm the happiest man because...since i tell to my wife that my work is finished for this Sunday morning....and we can go to the restaurant!!!,
Thanks again Ttelmah!
Wish you a great Sunday!
Manu |
A great outcome. The operation you are doing is actually a rotate. if you are regularly doing this, for example to drive christmas lights, then a much more efficient way to do this is to have two single byte indexes. The first points to the byte that holds the current offset into the array of the byte containing the first bit in the sequence and the second byte contains a bit mask pointing to the current bit. Instead of rotating the array you rotate the mask. if after rotating the mask, the byte value of the mask is zero then you set it to 1 (actually 0x01) and increment the offset pointer. If this pointer equals the size of the array then set it to 0
Seems more complex but significantly faster. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|