Thread: Bit Shifting question (simple)

  1. #1
    Registered User
    Join Date
    Oct 2006

    Bit Shifting question (simple)

    PORTB = DATA >> i;

    I am attempting to put a bit shifted version of DATA into PORT B
    question is:

    does the above line of code change the variable DATA at all, or is it still the original value that it had before this line of code??

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    DATA maintains its old value. It's just like a = b + c doesn't change the value of b.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Only the assignment operators (=, +=, >>=) change the value of their operands, and then only the lvalue is modified (the variable on the left).

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Question!!
    By gameuser in forum C++ Programming
    Replies: 2
    Last Post: 06-06-2009, 05:42 PM
  2. a simple question about pointers
    By bahada in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:15 AM
  3. byte and bit order question
    By chunlee in forum C Programming
    Replies: 7
    Last Post: 11-07-2004, 01:50 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM