Bitwise input/output

This is a discussion on Bitwise input/output within the C Programming forums, part of the General Programming Boards category; I'm reading about bit input/output on this link: Bit input/output It says: AND, if the bit from the second parameter ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    56

    Bitwise input/output

    I'm reading about bit input/output on this link:
    Bit input/output

    It says:
    AND, if the bit from the second parameter is 1, the bit from the first one is not modified. If it's 0, it will be changed to 0. We use to clear bits we don't care about.
    But then:

    For example if we only care about the rightmost bit, but the other ones could be non zero, we use AND. "011010" AND "000001", result: "000001".
    So...

    011010
    000001
    ---------
    000001


    Am I missing something? How come 0&1 is 1 is it's been stated that "if the bit from the second parameter is 1, the bit from the first one is not modified."?

    oh and btw, sorry if this is the wrong section to post it

  2. #2
    Registered User gaurav9991's Avatar
    Join Date
    Oct 2010
    Location
    Pune, Maharashtra, India
    Posts
    69
    you are correct, I'm agree with you

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by dhuan View Post
    Am I missing something? How come 0&1 is 1 is it's been stated that "if the bit from the second parameter is 1, the bit from the first one is not modified."?

    oh and btw, sorry if this is the wrong section to post it
    It would be correct if the second logic operation was an OR.

    FWIW... you can be fairly sure your lessons are sinking in when you start finding errors in the course materials.

  4. #4
    C-no_Ob Bennie98's Avatar
    Join Date
    Oct 2010
    Location
    Ledeberg, Ghent, East-Flanders, Belgium
    Posts
    49
    Quote Originally Posted by CommonTater View Post
    It would be correct if the second logic operation was an OR.
    that's what the course also says...

    For example if we have the binary value "0010" and OR it with "1110" we get "1110".

    First parameter 0110
    Second parameter 1010
    Result 1110
    so the course is actually contradicting itself
    Because Tetris Is Unrealistic.

    "The fear of death is the most unjustified of all fears, for there's no risk of accident for someone who's dead." - Albert Einstein

    "The Edge... there is no honest way to explain it because the only people who really know where it is are the ones who have gone over." - Hunter S. Thompson

    "I never think of the future. It comes soon enough." - Albert Einstein

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Bennie98 View Post
    so the course is actually contradicting itself
    Believe me this wouldn't be the first time I've found errors in coursewares.

    Of course 011010 AND 000001 = 0.

    As I said before it speaks well of your learning process that you caught it.
    Last edited by CommonTater; 11-04-2010 at 07:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Bitwise Operation..
    By ahmedBanihammad in forum C Programming
    Replies: 4
    Last Post: 10-31-2010, 09:11 AM
  2. Bitwise Operators
    By rrc55 in forum C Programming
    Replies: 6
    Last Post: 04-30-2009, 11:37 AM
  3. Bitwise Questions
    By someprogr in forum C Programming
    Replies: 8
    Last Post: 12-14-2008, 05:45 PM
  4. bitwise operations with double
    By henry_kay in forum C Programming
    Replies: 2
    Last Post: 10-03-2007, 04:57 AM
  5. Characters into bitwise ints
    By Code Zer0 in forum C++ Programming
    Replies: 9
    Last Post: 04-24-2003, 08:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21