Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Bit fields

2010-06-08 by Robert Adsett

On 6/7/2010 9:07 PM, David VanHorn wrote:
> Initially I was thinking that I'd do a bit array, set the unused bits
> to 1, the "not arrived yet bits" to 0, and then flip them to 1 as the
> packets arrive.  When the array ands to FF, then I'm done.   Seems
> simple in concept, but messy so far in C.

To set received bit

receive_fl |= 1 << pktnum;


To check all received

if( receive_fl == 0xFF) {}

Setting not used to one is a little more work but assuming that they are 
not scattered a very straightforward loop will do it.

receive_fl=0;
for( i =  first_not_rec; i < 8; i++) {
     receive_fl |= 1 << i;
     }

Obvious optimizations for known fixed receive groups left as an 
exercise.  Syntax errors and typos are to check if you are following ;)

Looks simple and clean to me.

Robert

-- 
http://www.aeolusdevelopment.com/

  From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time?  37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live....
we currently have stock."

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.