Re: Rotating through a four-bit nibble

"Kevin L. Clague" <[email protected]>
Newsgroups gmane.comp.hardware.lego.robotics
Organization None
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.