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 / 22638
22637  |  22639
Subject: 
Re: bitwise manipulations in C
Newsgroups: 
lugnet.robotics
Date: 
Fri, 6 Aug 2004 22:32:55 GMT
Viewed: 
1071 times
  
In lugnet.robotics, Scott Davis wrote:
Hi,
Can anybody tell me about bitwise manipulations or point me to a site that
explains what it is, what its used for, and how to use it?

Hi Scott,

Steve summed it up well. Here's a fairly simple example:
http://www.brickshelf.net/gallery/RoscoHead/towercrane/programming/remote.c

This processes data from a LEGO remote control, which arrives every few ms as a
"bit mask", with each 1 bit representing a pressed key on the remote. If you
look in lr_process(), it first checks if the data has changed from the previous
call (lr_data = data received, lr_curkeys = data saved from previous call).

If data has changed, it first does an '&', which assigns a bit-mask of all the
bits that are 1 in both, ie all the keys that are pressed that were also pressed
last time.

it then does a bitwise and with the complement of that against each of the
bitmasks, which returns bitmasks of the keys that have been pressed, and the
keys that have been released since last time, respectively. This is a little
tricky to explain in words, probably easier if you do a few exercises with a
4-bit value or something to see how it works.

Then it does the k loop, which cycles k through all the bits, 1 by 1, and calls
a user-defined function for each bit depending on whether the key has been
pressed or released.

Hope this helps.

ROSCO



Message is in Reply To:
  bitwise manipulations in C
 
Hi, Can anybody tell me about bitwise manipulations or point me to a site that explains what it is, what its used for, and how to use it? thanks, Scott ___...___ Express yourself instantly with MSN Messenger! Download today - it's FREE! (URL) (20 years ago, 6-Aug-04, to lugnet.robotics)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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