To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 24371
  Rotating through a four-bit nibble
 
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 (...) (19 years ago, 20-Sep-05, to lugnet.robotics)
 
  Re: Rotating through a four-bit nibble
 
(...) One way to do this might be by using multiplication and division. Temp = (Input & 0000 0000 0011 0000)*4 + (Input & 0000 0000 1100 0000)/4 Output = (Input & 1111 1111 0000 1111) & (Temp & 0000 0000 1111 0000) Although I imagine that can be (...) (19 years ago, 20-Sep-05, to lugnet.robotics)
 
  Re: Rotating through a four-bit nibble
 
(...) What are you optimizing for? Code clarity? Code speed? Code length? There are (to my knowledge) no truly pretty solutions to this. I would tend to go with: int rotbits(int input, int numbits, int offset, int rotdist) { int mask = (~((~0) << (...) (19 years ago, 20-Sep-05, to lugnet.robotics)
 
  Re: Rotating through a four-bit nibble
 
(...) Well, your example has the nibble of interest in the middle of the register. Due to boundary conditions, it might be cheaper to have it in the least significant bits of the 16 bit register. In your example you are rotating by an aribtrary (...) (19 years ago, 21-Sep-05, to lugnet.robotics)
 
  Re: Rotating through a four-bit nibble
 
(...) Since I didn't really complete the assignment I'll try again. I didn't honor the x bit request. I confirmed that even SDK v2.5 does not have shifts or rotates, and that in NQC you can only do shifts based on constant amounts. The two routines (...) (19 years ago, 21-Sep-05, to lugnet.robotics)
 
  Re: Rotating through a four-bit nibble
 
(...) Why in the world wouldn't the firmware support shifting? The hardware (URL) certainly does>. Heh, using multiply and divide to simulate shifting is kind of backwards. (19 years ago, 22-Sep-05, to lugnet.robotics, FTX)
 
  Re: Rotating through a four-bit nibble
 
"Jordan Bradford" <bradfj23REMOVE_THIS...uwosh.edu> wrote in message news:In7A20.1sK1@lugnet.com... (...) The problem is, multiplication and division to a binary CPU, as is the case here, is just a whole series of instructions. Here is the basic (...) (19 years ago, 22-Sep-05, to lugnet.robotics)
 
  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)
 
  Re: Rotating through a four-bit nibble
 
(...) 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 (...) (19 years ago, 22-Sep-05, to lugnet.robotics)
 
  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)
 
  Re: Rotating through a four-bit nibble
 
(...) Understand what better? Binary math? No problems with that! By "backwards" I meant that multiplication and division by powers of 2 are usually changed to shift L/R by compilers. Also, I am amused that because the firmware doesn't use the (...) (19 years ago, 22-Sep-05, to lugnet.robotics, FTX)
 
  Re: Rotating through a four-bit nibble
 
(...) Kev (...) Nice to hear from another bit twiddler.... (...) I do find it ironic that the firmware suports bitwise AND and OR, but not XOR, and also not shifts. Gack! Well, at least we're not having to use loops to add things to themselves to (...) (19 years ago, 22-Sep-05, to lugnet.robotics, FTX)
 
  Re: Rotating through a four-bit nibble
 
(...) With that limitation we'd be creating a register (or Turing) machine simulator, too. It would be interesting to see a real-world processor that only has increment and decrement instructions. I'm thinking the LEGO firmware doesn't support these (...) (19 years ago, 29-Sep-05, to lugnet.robotics, FTX)

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR