Jump to content

Bitwise operators


Jon
 Share

Recommended Posts

  • Administrators

With the GUi stuff you often have to AND/OR various values together to get the value you want and the BitAnd() / BitOr() functions are a bit nasty for this.

We've pretty much run out of operators so I was going to add in "bitand" "bitor" as new operators but that would mean the removal of the functions of the same name and that would break old scripts. Damn my naming conventions :D

Options are:

1. add new operators named BitAnd, BitOr etc and remove the functions - breaking existing scripts (we can only assume that games with their pixel scripts will already be using at least some ANDing)

2. add new operators bAnd, bOr and leave the functions in as well for backwards compatibility

3. Modify the existing bit functions to take lots of optional parameters (David suggested this ages ago) so you can do things like BitOr(1, 2, 3, 8, 16, 22)

Link to comment
Share on other sites

You could always use && for bit and and || for bit or. It might be confusing to C++ experienced people at first, but it's still somewhat logical, I guess.

My preference would be to see it as an operator and for it to be reallyshort, like 1 - 2 characters. Option 3 would be okay, but it's not as intuitive to use unless they are operators.

Link to comment
Share on other sites

  • Administrators

I had thought of the && thing but I thought it would have been completely backwards for the C people. There are BitXOR and BitNot as well which could complicate things further

&& BitAnd

|| BitOr

! BitNot (or !!)

^ is already power, so ^^ for bitxor

:D Hmmm...

Link to comment
Share on other sites

As an experienced C person (has it really been 15 years already?!), I can easily adapt to &&, ||, ^^, !! for bit-wise operators. As we are using & for concatination, ^ for power and ! for logical not, doubling up for all makes sense. Leave the functions for backwards compatibility. Besides, as a C person, I like being able to use operators to stick values together rather than functions.

$x = BitOR(BitOR(2, 8), BitOr(16, 32))

vs.

$x = 2 || 8 || 16 || 32

Turn the AND and OR operators into strictly logical operators. BTW, Can the same optimization that C does (not calling subsequent operations if the final value becomes known) be done in AutoIt for the logical operators?

Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

I pretty much agree with all of what David said. Even though C++ is the language I use most, I can easily adapt to doubling up the symbols if it means we get to use them as operators. Plus not breaking scripts (Or at least moving things into a deprecation phase first) is always good, as well.

Link to comment
Share on other sites

  • Administrators

Can the same optimization that C does (not calling subsequent operations if the final value becomes known) be done in AutoIt for the logical operators?

It's done this for a while :D

If Func1() AND Func2() Then

If Func1 returns false then Func2 will not be run.

Link to comment
Share on other sites

AutoIt is written in C++ (a de facto standard programming language), which uses &&, || and ! as logical operators only. Using them as bit operators in AutoIt is IMHO not the best option, as it easily could lead to confusion. If & and ^ wasn't already used, it would be nice to use the C bit-operators: &,|,^,~. But as it stands, I belive option #2 is the best:

$x = 2 bOR 4 bOR 8 bOR 16 bOR 32

If you really want to use C-like bit-operators, an alternative could be adding a prefix character to them, e.g. backslash: \& \| \^ \~ for bit -and,-or,-xor,-not:

$x = \~(2 \| 3 \| 4)

It's done this for a while 

If Func1() AND Func2() Then

If Func1 returns false then Func2 will not be run.

Great. I presume that also applies for:

If Func1() OR Func2() Then ...

If Func1 returns true then Func2 will not be run?

(not using v102 yet, else I simply would test it).

Edited by tylo

blub

Link to comment
Share on other sites

  • Administrators

Great. I presume that also applies for:

If Func1() OR Func2() Then ...

If Func1 returns true then Func2 will not be run?

(not using v102 yet, else I simply would test it).

It should be like that in .101 and even .100

I'm pretty sure I got this change in before the initial release...

Link to comment
Share on other sites

AutoIt is written in C++ (a de facto standard programming language), which uses &&, ||  and ! as logical operators only. Using them as bit operators in AutoIt is IMHO not the best option, as it easily could lead to confusion. If & and ^ wasn't already used, it would be nice to use the C bit-operators: &,|,^,~. But as it stands, I belive option #2 is the best:

$x = 2 bOR 4 bOR 8 bOR 16 bOR 32

If you really want to use C-like bit-operators, an alternative could be adding a prefix character to them, e.g. backslash: \&  \|  \^  \~ for bit -and,-or,-xor,-not:

$x = \~(2 \| 3 \| 4)

Actually there is a very well-defined standard for C++ :) . C++ is being used because of the power we can get out it and we need the low-level interfaces to make AutoIt do all we want it to.

I tend to figure out when I am programming in C/C++ and in AutoIt pretty easily. The changes in operators is not big deal. Anybody else remember APL? :huh2:

\| That is just ugly, IMHO. :D

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

\| That is just ugly, IMHO.

Ok, I admit It's not the nicest.

Yeah, we can all adapt, but why squeeze in those strange C++ bitoperator characters anyway?

I think BAND, BOR, BXOR, BNOT is fine, and follows the style of AutoIt's AND, OR,.. operators. Enough said on this issue from me. :D

blub

Link to comment
Share on other sites

  • Administrators

Ok, I admit It's not the nicest.

Yeah, we can all adapt, but why squeeze in those strange C++ bitoperator characters anyway?

I think BAND, BOR, BXOR, BNOT is fine, and follows the style of AutoIt's AND, OR,.. operators. Enough said on this issue from me.  :D

VBScript actually uses AND for both logical and bitwise AND which baffles the hell out of me as they work completely differently and have different levels of precedence too. Must be some egg heads working on that code :huh2: Edited by Jon
Link to comment
Share on other sites

Something-Heads anyway! :)

So, do we want to use Band, Bor, BNot, BXor or &&, ||, !!, ^^ for the binary operators. I'm going to try that polling feature.

While we are at it, can add % for Mod? :D:huh2:

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

I have added a poll to ask for opinions on this. Vote and we can check out in a few days (or whenever) to see how things are going on it.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

  • 2 weeks later...

Oh, no! We are tied in the poll. We need more people to vote.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

BOr, BAnd, etc. would be the operators, not functions, as in:

$x = $flags BAnd 64

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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...