Whats the difference?
Moderator: InsideQC Admins
5 posts
• Page 1 of 1
Whats the difference?
I have used "&&" many times which means "and" right?
I have used "||" which is "or" correct?
I have recently came across " | " which looks to me like it means "and" as well.
So what is the difference between "&&" and "|"?
I have used "||" which is "or" correct?
I have recently came across " | " which looks to me like it means "and" as well.
So what is the difference between "&&" and "|"?
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
Re: Whats the difference?
Ghost_Fang wrote:I have used "&&" many times which means "and" right?
I have used "||" which is "or" correct?
I have recently came across " | " which looks to me like it means "and" as well.
So what is the difference between "&&" and "|"?
Incorrect, | and & are bitwise operators meaning & is "bitwise and" and | is "bitwise or". You may have to understand a bit of binary to fully understand them. In quakec they are most commonly used with flags as flags are powers of 2.
http://en.wikipedia.org/wiki/Bitwise_operation
- GiffE
- Posts: 170
- Joined: Sun Oct 08, 2006 3:39 pm
- Location: USA, CT
Let's say that the variable `x` has a value of 13, and `y` a value of 32. In
binary, 13 is represented as `11001`. To understand this, I've made this table:
As you can infer from this, `y` would be written as `100000`. With a bitwise or,
the result is 1 if the first bit is 1 or the second bit is 1, otherwise the result is 0.[1]
With a bitwise and, the result is 1 if the first bit and the second bit are 1, and 0 otherwise.[1]
Hope that helps.
[1]http://en.wikipedia.org/wiki/Bitwise_operation
binary, 13 is represented as `11001`. To understand this, I've made this table:
- Code: Select all
128 64 32 16 8 4 2 1
0 0 0 0 1 1 0 1
As you can infer from this, `y` would be written as `100000`. With a bitwise or,
the result is 1 if the first bit is 1 or the second bit is 1, otherwise the result is 0.[1]
- Code: Select all
00001101
|00100000
---------
00101101
With a bitwise and, the result is 1 if the first bit and the second bit are 1, and 0 otherwise.[1]
- Code: Select all
00001101
&00100000
---------
00000000
Hope that helps.
[1]http://en.wikipedia.org/wiki/Bitwise_operation
Ken Thompson wrote:One of my most productive days was throwing away 1000 lines of code.
Get off my lawn!
-

dreadlorde - Posts: 268
- Joined: Tue Nov 24, 2009 2:20 am
Yea, Baker explained a bit of binary before to me somewhere. And for once.... I completely understand! lol.
Thanks guys, I know a bit more now
Thanks guys, I know a bit more now
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest