CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Shift Left a complete 128 bytes Array of 1 bit

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Manu59114



Joined: 22 Jan 2018
Posts: 34
Location: North of France

View user's profile Send private message

Shift Left a complete 128 bytes Array of 1 bit
PostPosted: Sun Sep 16, 2018 2:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 16, 2018 3:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 16, 2018 3:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 16, 2018 5:12 am     Reply with quote

That's a successful outcome!. Smile
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Sep 16, 2018 11:46 pm     Reply with quote

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!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group