What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
Go Back  Xtreme Visual Basic Talk > > > What in the world does the "Or" do as a mathematics operator?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2010, 06:18 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default What in the world does the "Or" do as a mathematics operator?


I was messing around in VB 2010 Express when I typed the following and got the following results...

x = 1 or 2
Result: x = 3

x = 2 or 3
Result: x = 3

x = 90 or 99
Result: x = 123

You can type them in the immediate window too:
?1 or 2

Can anyone explain to me what in the world the "or" is doing with these two numbers? I was experimenting trying to find a quick easy way to pick randomly between two numbers.. oh well.. perhaps I've stumbled upon something else???
Reply With Quote
  #2  
Old 06-21-2010, 06:29 PM
lordofduct's Avatar
lordofduct lordofduct is offline
Centurion
 
Join Date: May 2010
Location: south florida yo
Posts: 120
Default

OR is part of boolean arithmetic... which means we need a 2 part boolean representation of the value. So basically we need to look at the number as binary to get it.

So OR basically means if one or the other is true, then true... otherwise false.

true true = true
true false = true
false true = true
false false = false

now in the binary, this means for every digit if one or the other is one, then that space is one in the result.

5 OR 2
101(2) OR 10(2)

101
010
---
111

111(2) = 7(dec)


this is why 1 OR 2 is 3:

01
10
--
11

11(2) = 3(dec)

more examples:

6 OR 5 = 7

110
101
---
111


17 OR 20 = 21

10001
10100
------
10101
__________________
I'm a turtle... woooo
Reply With Quote
  #3  
Old 06-21-2010, 06:33 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

Wow, thanks. That answers my question.
Reply With Quote
  #4  
Old 06-21-2010, 06:53 PM
webbone's Avatar
webbone webbone is offline
Hydrogen Powered

Administrator
* Expert *
 
Join Date: Jul 2003
Location: Sacramento, CA
Posts: 6,090
Default

lordofduct has demonstrated how the BITWISE OR operator works. Note that OR can also be a LOGICAL operator:

Quote:
Originally Posted by MSDN
Dim a As Integer = 10
Dim b As Integer = 8
Dim c As Integer = 6
Dim firstCheck, secondCheck, thirdCheck As Boolean
firstCheck = a > b Or b > c
secondCheck = b > a Or b > c
thirdCheck = b > a Or c > b

The preceding example produces results of True, True, and False, respectively.
See the complete explanation in MSDN - http://msdn.microsoft.com/en-us/library/06s37a7f.aspx
__________________
"With the appearance of the AddressOf operator, an entire industry has developed among authors illustrating how to do previously impossible tasks using Visual Basic. Another industry is rapidly developing among consultants helping users who have gotten into trouble attempting these tasks." -Dan Appleman
Reply With Quote
  #5  
Old 06-22-2010, 08:01 AM
AtmaWeapon's Avatar
AtmaWeaponWhat in the world does the "Or" do as a mathematics operator? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Note that the most common reason you use the bitwise operators is with bitfields or flags enumerations like FileAttributes. Wikipedia's Mask (computing) article has as good an explanation of how you work with these as I could give.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #6  
Old 06-22-2010, 08:15 AM
OnErr0r's Avatar
OnErr0rWhat in the world does the "Or" do as a mathematics operator? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

__________________
Quis custodiet ipsos custodues.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator? What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
 
What in the world does the "Or" do as a mathematics operator?
What in the world does the "Or" do as a mathematics operator?
 
-->