Rotating through a four-bit nibble

"Brian Davis" <[email protected]>
Newsgroups gmane.comp.hardware.lego.robotics
Organization None
Message-ID <[email protected]>
   No, it's not pornographic (look over in rtlToronto - I hear it's a fun
thread). But I'm working in NQC, and I need to rotate the bit series in a 4-bit
(or 8-bit) nibble embedded in a 16-bit word. Annoying. Any suggestions? Masking
the desired four bits out of a storage variable and into a temporary variable
four times (so it's a repeating pattern) and then rotating and masking out the
desired sequence might work, but is there a better way? Bit-level manipulation
is not my strong suite.

(x's here are "something else" that I may wish to keep intact, y is garbage or
potentially trashed bits)

stored sequence in 16-bit word:        xxxx xxxx 0110 xxxx
4-bit nibble copied across temporary:  xxxx 0110 0110 0110
left shift temporary, say, twice:      xx01 1001 1001 10yy
mask out one nibble back into storage: xxxx xxxx 1001 xxxx

There's got to be a better way. I'm using NQC, so I'm stuck with those big
16-bit words and basic operations like bit logic, shifts, and interger division
(and of course modulo division).

   Anybody?

-- 
Brian Davis
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.