Subject:
|
Re: Rotating through a four-bit nibble
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Thu, 22 Sep 2005 18:45:09 GMT
|
Viewed:
|
1677 times
|
| |
 | |
In lugnet.robotics, Brian Davis wrote:
> In lugnet.robotics, Kevin L. Clague wrote:
>
> > Since I didn't really complete the assignment I'll try again.
>
> Both your 1st & 2nd solutions are very good; thanks to you and other posters
> to this thread for giving me a much better handle on binary manipulations, and
> solutions to this problem. In answer to an earlier question, speed is important
> (simple (ie- no loop) maze solving for a line-follower), but so is size because
> this program is getting long fast. I'd like an entry for the ChiBots event which
> is a maze of 7x7 potential nodes, so bit representations for some things are
> going to save some variable space. As well as being a more "natural" way of
> doing it.
>
> > I confirmed that even SDK v2.5 does not have shifts
> > or rotates
>
> I guess I shouldn't have been too surprised by this - after all, it's aimmed
> at programming for kids, so such "low level" operations aren't going to be used
> very often (at all). Still, bit of a surprise - I was assuming I should use the
> shift operator for speed. Oh well.
>
> Now I need to figure out good ways to code all this (I've almost got the
> movement and detection routines polished, and the mechanical aspects were easy
> (because I'm reusing an older platform). Now I'm bumbing up against the memory &
> speed limitations of the standard firmware (but it's taken me something like
> four years to get there, so I'm not complaining).
Maybe it is time to move on to BrickOS?
int
rotate_right(
int value, // the value to be rotated
int width, // the width of the rotated field
int base, // bitnumber of rightmost bit in rotate field
int amount) // the amount to rotate between base and base+width)
{
int r,l;
r = value >> amount;
l = value << width - amount;
r &= (1 << (base + amount)) - (1 << base);
l &= (1 << (base + width)) - (1 << (base + amount));
value &= ~((1 << (base + width)) - (1 << base);
value |= r | l;
}
Kev
|
|
Message has 1 Reply:  | | Re: Rotating through a four-bit nibble
|
| (...) BrickOS has mocked me from the horizon for some time, but there are two things that are holding me back: (a) Judging by the posts and what I've read, the learning curve seems awfully steep - especially since I'm on a Mac. (b) Rarely have I (...) (19 years ago, 22-Sep-05, to lugnet.robotics)
|
Message is in Reply To:
 | | Re: Rotating through a four-bit nibble
|
| (...) Both your 1st & 2nd solutions are very good; thanks to you and other posters to this thread for giving me a much better handle on binary manipulations, and solutions to this problem. In answer to an earlier question, speed is important (simple (...) (19 years ago, 22-Sep-05, to lugnet.robotics)
|
13 Messages in This Thread:   
  
          
           
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|