Go to Post Defense is not at all anti-GP. - Wetzel [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 18-02-2008, 09:48
Roger Roger is offline
Registered User
FRC #1153
 
Join Date: Jan 2006
Rookie Year: 1900
Location: Walpole MA
Posts: 685
Roger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond repute
Re: joystick and extra buttons

& is a "bitwise and" operator. Think of it converting the two numbers to binary, then wherever the two numbers both have a "1" in the same place, keeps the "1", otherwise clears it to "0".

7 & 2 returns a 2 (00000111 & 00000010 returns a 00000010)

| is a "bitwise or" operator -- if either bit has a 1 it returns a 1. If both bits are 0 it returns a 0.

^ is a "bitwise exclusive OR" (sometimes known as XOR). Returns a 1 if either number has a 1 but not both, otherwise a 0.

~ is "bitwise NOT" (one's complement). Returns the opposite number (1 to 0, 0 to 1).

Note they all operate on the bits (as in binary numbers).

There used to be more combinations in BASIC's wild days (when Basic was BASIC), but I guess C isn't as wild.

Do not confuse & and &&, and | and ||. The latter symbols apply to the whole number, not to the bits.

<< shifts each bit to the left (sort of like multiplying by 2 each time). >> shifts each bit to the right (dividing by 2 each time). In your case X<<7 shifts all the bits in X to the left by 7: 0000.0001 to 1.0000.0000 (I put in decimal points to make it clearer). You'll have to find out what p3_aux produces in the lowest bit, then all the other bits are cleared, it then shifts it left 7 bits.

X?0:1 I think evaluates X, then returns a 0 if true, or 1 if false. It's a shorthand if statement. So after doing the above, it is evaulated true (1), it returns a zero, else if it is false (0) it returns a one, and is put into p3_sw_5. (a true might be from any non-zero value, and false is always zero.)

I don't know offhand the precidence of which does what first. I am assuming it is ((p3_aux & 1) << 7), not (p3_aux & (1 << 7)), but looking again I can't tell and I don't remember.

Find yourself a book on C -- it's all in there!

Roger.
_______________________________
Always do right! This will gratify some people and astonish the rest. - Mark Twain
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Buttons to Pins on Joystick yarb65 Electrical 1 24-08-2007 20:39
Programming Extra Joystick Buttons Inverted Programming 2 08-02-2007 11:45
Buttons, Buttons and more Buttons (2006) Freddy Schurr Team Organization 11 14-12-2005 21:36
joystick buttons and a quick question h0x4r Programming 2 17-02-2005 00:18
Using the extra buttons on the joystick. Code\\Pilot Programming 7 04-12-2004 19:30


All times are GMT -5. The time now is 17:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi