|
-
Aug 30th, 2002, 01:28 PM
#1
Thread Starter
Frenzied Member
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!
-
Aug 30th, 2002, 03:21 PM
#2
Frenzied Member
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 
-
Aug 30th, 2002, 03:39 PM
#3
Thread Starter
Frenzied Member
I relized now that theres all of these operators...
&&
==
||
&
=
|
^
%
<<
Whats the difference between using a | and ||?
-
Aug 30th, 2002, 06:38 PM
#4
Monday Morning Lunatic
| 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
-
Aug 30th, 2002, 06:58 PM
#5
Member
Originally posted by parksie
| is bitwise, || is logical. For example:
3 | 1 = 3
3 || 1 = true
for basic stuff ull want ||
-
Sep 2nd, 2002, 04:27 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|