473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can someone explain?

I'm looking at some code that i've inherited and I'm not really familar with
what's going on here and was hoping somone could explain it to me.

For reference:

f1 is a long
f2 is a long

here's the statement

f1 = (f1 or f2)

I'm curious what the "OR" is doing here. I assume it's some type of
comparison and reassignment based on the comparison but like I said, I'm not
sure I've ever seen this type of operation before and would like someone to
try and explain what's going on here.

Thanks
Jul 1 '08 #1
6 1199
"Dave Young" <dm******@yahoo.comschrieb
f1 = (f1 or f2)

I'm curious what the "OR" is doing here. I assume it's some type of
There's the helpful [F1] key on your keyboard. Can lead you to:

http://msdn.microsoft.com/en-us/library/06s37a7f.aspx
Armin
Jul 1 '08 #2
Hello Dave,
For reference:

f1 is a long
f2 is a long
here's the statement

f1 = (f1 or f2)

I'm curious what the "OR" is doing here. I assume it's some type of
comparison and reassignment based on the comparison but like I said,
I'm not sure I've ever seen this type of operation before and would
like someone to try and explain what's going on here.

Imagine that before this statement the following is true.
f1 = 7 = 00000111 (bin 7)
f2 = 24 = 00011000 (bin 24)

the statement says set f1 equal to a value equivilent to the ORing of both
values.

ie if the f1 has a 1 in a given position OR f2 has a 1 in that same position
then the output value should have a 1 in that same position

f1 therefore becomes 00011111 = 31

in this case it appears to have resulted in addition

However.... imagine that the figures were 15 and 28
15 = 00001111
28 = 00011100
f1 = 00011111 = 32

32 is definitly not the result of adding 15 and 28

It can be looked on as the combination of flags.

It looks like in you example code.... someone was trying to flip all the
bit on in f1 which were on in f2 without turning off any of the bits which
were already on in f1.

Also be on the lookout for code which uses the AND (bitwise) operator

This sets the output bits only where both input bits are 1. this is used
for finding out the intersection of 2 sets of flags (ie what they have in
common)

It's late here. I hope some of this makes sense. :)

--
Rory
Jul 1 '08 #3
Thanks Rory

Guess it's time to study up on bitwise operators.

"Rory Becker" <ro********@newsgroup.nospamwrote in message
news:3a**************************@news.microsoft.c om...
Hello Dave,
>For reference:

f1 is a long
f2 is a long
here's the statement

f1 = (f1 or f2)

I'm curious what the "OR" is doing here. I assume it's some type of
comparison and reassignment based on the comparison but like I said,
I'm not sure I've ever seen this type of operation before and would
like someone to try and explain what's going on here.


Imagine that before this statement the following is true.
f1 = 7 = 00000111 (bin 7)
f2 = 24 = 00011000 (bin 24)

the statement says set f1 equal to a value equivilent to the ORing of both
values.

ie if the f1 has a 1 in a given position OR f2 has a 1 in that same
position then the output value should have a 1 in that same position

f1 therefore becomes 00011111 = 31

in this case it appears to have resulted in addition

However.... imagine that the figures were 15 and 28
15 = 00001111
28 = 00011100
f1 = 00011111 = 32

32 is definitly not the result of adding 15 and 28

It can be looked on as the combination of flags.

It looks like in you example code.... someone was trying to flip all the
bit on in f1 which were on in f2 without turning off any of the bits which
were already on in f1.

Also be on the lookout for code which uses the AND (bitwise) operator

This sets the output bits only where both input bits are 1. this is used
for finding out the intersection of 2 sets of flags (ie what they have in
common)

It's late here. I hope some of this makes sense. :)

--
Rory


Jul 1 '08 #4
Dave,
Guess it's time to study up on bitwise operators.

Keep in mind that they are from the age that memory (in fact bits) were very
expensive.

Cor

Jul 2 '08 #5


"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:B2**********************************@microsof t.com...
Dave,
>Guess it's time to study up on bitwise operators.

Keep in mind that they are from the age that memory (in fact bits) were
very expensive.

Cor
That being said, you can come to the same results using the FlagsAttribute
on an enumeration.

Mythran

Jul 3 '08 #6
On Jul 1, 4:39 pm, Rory Becker <rorybec...@newsgroup.nospamwrote:
However.... imagine that the figures were 15 and 28
15 = 00001111
28 = 00011100
f1 = 00011111 = 32

32 is definitly not the result of adding 15 and 28
It's late here. I hope some of this makes sense. :)
Must be why you got 32 out of that OR rather than 31 which is the
correct answer! :)

Chris
Jul 8 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
6
by: Ken Varn | last post by:
Sometimes when I try to close my managed C++ application, the following dialog displays in Win 2000 Pro: The title of the dialog is "Server Busy". The message is "This action cannot be completed...
8
by: Peter Foti | last post by:
I'm working on a site and the client said he thinks "the main title should be around 28pt and the subtitle probably 18pt". I know pt's are bad, and I want to convince him that he should NOT be...
5
by: J Allen Horner | last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an example: ----------- #include <stdio.h> #define MAX 10 int a; int rand_seed=10;
5
by: klj_mcsd | last post by:
Let's say you set txtlastname1.visible = true Then DirectCast(Page.FindControl("txtLastName1"), TextBox).Visible = False Why when you check txtlastname1.visible it is equal to True?
4
by: Richard L Rosenheim | last post by:
Using Visual Studio 2003 running under Windows XP Pro w/SP 1, when I create a new form, the form's title bar has the Windows 2000 look. Yet, in the various Microsoft demos, the form's title bar...
3
by: Jan Nielsen | last post by:
Hi I am working with rowfilters in dataviews. I would like to filter for empty fields (= null value in the database) I found this sentence on msdn: **************** To return only those columns...
1
by: Simon Windsor | last post by:
Hi I have just recevived this error could not write to hash-join temporary file: No space left on device Can someone please explain how I can stop this occuring. Whereis the hash-join...
1
by: mansa | last post by:
a) A company receives hundreds of orders every week through the mail. Explain carefully how BATCH- PROCESSING might be used. Describe the role of the BATCH TOTAL in this process. Explain how batch...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.