Results 1 to 6 of 6

Thread: Im trying to learn C++

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Talking Im trying to learn C++

    through the last week ive been trying to learn C++.

    I want to list all the things that I know so far about operators
    and see if they are true..

    I have a question at the end to


    C++ Operators
    ---------------------------------

    Code:
    ==         Equal to
    &&         And
    |            Or
    <<         And 4 strings? Only with the COut, and CIn ?

    As for a binary comparisons...

    Code:
    int var = 2;
    If(var && 0x002) {var++}
    I dont understand why that arg returns true

    Little help???

    Thanks!

  2. #2
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    Im pretty sure that since 2 and 0x002 is not equal to 0, its true (nonzero is true).
    Also, << is a bitwise operator. Look at "Thinking in C++" (free ebook) and it explains it well. It is overloaded in cin and cout (means that they reassigned different functions to the operators)
    retired member. Thanks for everything

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    I relized now that theres all of these operators...

    &&
    ==
    ||
    &
    =
    |
    ^
    %
    <<

    Whats the difference between using a | and ||?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    | is bitwise, || is logical. For example:

    3 | 1 = 3
    3 || 1 = true
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Member Aerials's Avatar
    Join Date
    Jul 2002
    Location
    Chile
    Posts
    50
    Originally posted by parksie
    | is bitwise, || is logical. For example:

    3 | 1 = 3
    3 || 1 = true
    for basic stuff ull want ||

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Binary operators

    All numbers are represented in memory as a chain of bits (duh!). Using the bitwise operators you can modifiy those bits in some interesting ways.
    Let's have the numbers 12 (1100) and 10 (1010). The bitwise operators act on the single bits of those numbers.
    a) bitwise logical operators: &, |, ^
    They perform the same thing as their normal counterparts, but for every single bit:
    1100 & 1010 -> bitwise and
    [code]
    1100
    &&&&
    1010
    ----
    1000
    [code]
    1100 | 1010 -> bitwise or
    Code:
    1100
    ||||
    1010
    ----
    1110
    ^1100 -> bitwise not
    =0011

    b) bitshift: <<, >>
    shifts the bits of a number to the left or right
    00001100 (12) << 3 =
    01100000 (96)

    01010000 (80) >> 3 =
    00001010 (10)

    Those operators are mainly for advanced use: optimizing and bit-fields.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width