Jump to content

BitOR and BitAND... please school me on usage


Recommended Posts

I've never understood how BitOR/BitAND/BitNOT functions work. The helpfile explanation only adds to my confusion. Can someone help break down what its use is and help me to see the brilliance of these functions? Layman's terms highly appreciated ;)

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Bit* operations perform exactly what they say they do: apply a basic binary operator (NOT, AND, OR, XOR) to the parameters passed, seen as 32- or 64-bit values.

Operands are not "seen" as integers, but only as a series of 32- or 64-bits. Each bit position in the result is the operator applied to corresponding bit from the inputs. Explanations found i.e. here.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Bit* operations perform exactly what they say they do: apply a basic binary operator (NOT, AND, OR, XOR) to the parameters passed, seen as 32- or 64-bit values.

Operands are not "seen" as integers, but only as a series of 32- or 64-bits. Each bit position in the result is the operator applied to corresponding bit from the inputs. Explanations found i.e. here.

So it's like doing a If ... OR ... OR ... OR ... Then ... etc?

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

No, not If, or at least not the simplest way to see it.

Read the Wikipedia page linked.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I have... and the article is still too foggy for me to understand. I see what they are saying: it calculates the operand (and/or/etc) at the bit level (which means if it's a string it breaks them down to their bit values?)... but at my level of comprehension, I don't see its use or value.

Is there something else I should be reading into to understand the importance and use of bitwise comparisons?

I suppose I look at these things as "what does it do... how can I use it... what can I use it for". I see the "what does it do" but I don't understand the "how can I use it" thus I wouldn't know what I could use it for in any of my projects.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Binary operands are 32-bit integers and nothing else. It's rumored that future versions of AutoIt will allow for 64-bit binary operation too.

What to use it for? Mostly for packing many binary values into one single parameter.

For instance define individual bits in a status or option word to have an individual meaning. Look at how lines below

; Window Extended Styles

in WindowsConstants.au3 define individual bits to denote the style of the window you want.

When you invoke GUICreate, you pass extended style parms into one parameter, by using BitOR(option1, option2, ...).

Say some function like GUICreate gets passed a Int parameter $WinParams with those options stacked together (using BitOr).

That function would have to test bits to know how to behave. It would then BitAND the particular option constant to isolate the actual bit you passed.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

BitMask value -> Using the single bits (in a byte or bytes) as True/False flags.

So with a byte you have 8 options you can store in it. (or 32 options with a autoit int32)

(Kinda like a 1dim-array with only true/false data.)

Saves memory and/or variable names. (which ever is more important in whatever case.)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

;) I think of it a bit like light switches. Let's say we have three people who switch on different lights in the house. Two of the people turn on the same light every time. Turning the same light on twice is the same as turning the light on once: the light will be on regardless of how many people hit the switch. With BitOR I can determine how many lights will be on in the house after everyone has hit their sequence of switches. The only lights which will remain off are the ones which nobody switched on.

Now compare this example with description found in the help file.

BitOR returns 0 in each bit position where all input arguments have a 0 in the corresponding

position and 1 wherever there is at least one 1-bit.

Edited by czardas
Link to comment
Share on other sites

[power]----------[light]-----.
[input]----.                 |
           |                 |
           :----[switch1]----:
           |                 |
   OR      :----[switch2]----:
           |                 |
           :----[switch3]----:
           |                 |
           .----[switch4]----.


[power]----------[light]--------------------------------------------.
[input]----.                                                        |
           |                                                        |
   AND     .----[switch1]----[switch2]----[switch3]----[switch4]----.

[just bored]

[+ definitively don't like forum message edit box behavior.]

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

If you have one or two bits you may perform certain bitwise operations upon them.

Not

You may apply a not operation on one bit. This flips the bit so that zero becomes one and vice versa.

For two bits your options increase to and, or, and xor.

And

To and two bits together is to say that if both bits are one and only one then the result will be one. Otherwise, if one or both bits are zero then the result will be zero. The truth table for and follows.

| 0 1
-----------
0 | 0 0
1 | 0 1

Or

To or two bits is to say that if one or both bits are one then the result is one.

| 0 1
-----------
0 | 0 1
1 | 1 1

Xor

To xor (exclusive or) two bits is to say that if one and only one bit is one then the result will be one, otherwise zero.

| 0 1
-----------
0 | 0 1
1 | 1 0
Edited by LaCastiglione
Link to comment
Share on other sites

This is a luxury school: one student, many teachers!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...