Bitwise Explanation in the Form of a Question

This is a discussion on Bitwise Explanation in the Form of a Question within the C++ Programming forums, part of the General Programming Boards category; Bitwise AND adds bits together, and if two 1's line up, it's a 1, otherwise, it's a 0, like so, ...

  1. #1
    People Love Me
    Join Date
    Jan 2003
    Posts
    412

    Thumbs up Bitwise Explanation in the Form of a Question

    Bitwise AND adds bits together, and if two 1's line up, it's a 1, otherwise, it's a 0, like so, yes?
    Code:
      0011
    & 1010
    = 0010
    So, in an if statement:
    Code:
    int y=2; //0010
    if (y & 3)//0011
    {
    cout<< "This is true.";
    }
    So that means if just one of the resulting bits is 1, the condition is true?

    So saying if (y & 3) is the same as saying if (y==1 || y==2 || y==3), yes?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,643
    >> So that means if just one of the resulting bits is 1, the condition is true?
    Zero if false, everthing else is true.

    >> So saying if (y & 3) is the same as saying if (y==1 || y==2 || y==3), yes?
    Yep.

    >> Bitwise AND adds bits together...
    Not really "adds", rather "both have to be 1 to get a 1".

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling datas from another form?
    By Aga^^ in forum C# Programming
    Replies: 2
    Last Post: 02-06-2009, 01:17 AM
  2. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  3. Question about getting an info class from another Form
    By Joelito in forum C# Programming
    Replies: 0
    Last Post: 10-16-2006, 01:02 PM
  4. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 03:44 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM

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