# Anim8or Community

• August 05, 2024, 11:48:49 pm
• Welcome, Guest

### News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Pages: [1] 2

### AuthorTopic: ASL integer bit-wise operators  (Read 29637 times)

#### Steve

• Hero Member
• Posts: 2124
##### ASL integer bit-wise operators
« on: March 05, 2014, 05:26:09 pm »

Build 1071 adds the integer bit-wise operators &, ^, |, << and >>. Since there is no unsigned int in ASL the right shift always sign extends.

Build 1075 adds bit negate ~, and ++ and --.

Note: Build 175 had a bug parsing prefix ++ and -- so it was replaced by build 1076.
« Last Edit: March 26, 2014, 11:17:51 pm by Steve »
Logged

#### Raxx

• Hero Member
• Posts: 1482
##### Re: ASL integer bit-wise operators
« Reply #1 on: March 15, 2014, 11:09:09 am »

Hey Steve,

Finally able to give these operators a shot (trying to implement this algorithm), but couldn't help but notice that the bit-wise NOT (~) operator is missing. Granted, it can be done manually, but it'd be awesome if it were in there.

Thanks
Logged

#### Claude

• Sr. Member
• Posts: 285
##### Re: ASL integer bit-wise operators
« Reply #2 on: March 15, 2014, 01:54:30 pm »

Raxx

Until it's implemented,you could also apply XOR ^ between your integer and one which is all 1s to get the equivalent of a twiddle.

Hope it helps.
Claude
Logged

#### Raxx

• Hero Member
• Posts: 1482
##### Re: ASL integer bit-wise operators
« Reply #3 on: March 15, 2014, 05:06:40 pm »

Hey Claude, makes perfect sense, totally ignored the XOR operator there.

I came up with this solution via code, but I'm wondering if there's a less intensive method of determining the all 1-bit integer. Scratch that
« Last Edit: March 15, 2014, 07:47:12 pm by Raxx »
Logged

#### Claude

• Sr. Member
• Posts: 285
##### Re: ASL integer bit-wise operators
« Reply #4 on: March 15, 2014, 06:34:37 pm »

return \$int  ^  0xffffffff;

Haven't tested it,but It should work.
Logged

#### Raxx

• Hero Member
• Posts: 1482
##### Re: ASL integer bit-wise operators
« Reply #5 on: March 15, 2014, 07:35:59 pm »

Hum...it works, apparently as it should. I think I'm just a little confuzzled about the bitwise NOT operation overall. Time to read up on it!

Thanks Claude, simplifies things tremendously.
Logged

#### Claude

• Sr. Member
• Posts: 285
##### Re: ASL integer bit-wise operators
« Reply #6 on: March 15, 2014, 08:55:45 pm »

Sorry,didn't have much time when I posted.

In case this 0xffffffff is the confusing part,I should explain.
In ASL, an int is a 32-bit signed integer. Constants may be hexadecimal.
So,we define our constant as 0xffffffff

0x indicates that the following characters are hexadecimal.
Each character represents 4 bits(4 zeros or ones).
Example:

Code: [Select]
`0x0       0       0       0       0        f         c        6  0000    0000    0000    0000    0000     1111      1100     0110`
Read the first 2 paragraphs and look at the table lower on the right
side.

So, 0xffffffff gives us a 32 bits of 1.

If you already knew,it's OK.It might help someone else
interrested in ASL.
Logged

#### Raxx

• Hero Member
• Posts: 1482
##### Re: ASL integer bit-wise operators
« Reply #7 on: March 15, 2014, 09:38:46 pm »

Hey Claude, nice explanation. I pretty much knew that part (a good refresher though ), but like you said it could help someone else.

My main confusion was, I thought NOT was supposed to flip just the numbered bits, not the entire 32-bit span.

For example, my assumption was:

Int: 244 (0xf4)
Normal: [0000  0000  0000  0000  0000  0000]  1111 0100
Assumed NOT: [0000  0000  0000  0000  0000 0000]  0000 1011
Actual NOT: [1111  1111  1111  1111  1111  1111]  0000  1011 (int value: -245)
Logged

#### Claude

• Sr. Member
• Posts: 285
##### Re: ASL integer bit-wise operators
« Reply #8 on: March 15, 2014, 10:42:13 pm »

I understand.

In C and C++,the bitwise complement operator flips every bit.
Since ASL most of the time follows the same rules,
we may assume that it will be like that.
The XOR operation is used as a sort of selective
complement operator.
Bitwise operators are not something I've used very often.Feels like a  refresher course to me too.

Bye
Claude
Logged

#### Steve

• Hero Member
• Posts: 2124
##### Re: ASL integer bit-wise operators
« Reply #9 on: March 16, 2014, 04:55:11 pm »

(I guess I should look at the C++ spec occasionally instead of trying to remember everything myself - getting too old for that!)
Logged

#### Steve

• Hero Member
• Posts: 2124
##### Re: ASL integer bit-wise operators
« Reply #10 on: March 25, 2014, 09:42:33 pm »

Bumping topic so it's apparent that I updated it.
Logged

#### Raxx

• Hero Member
• Posts: 1482
##### Re: ASL integer bit-wise operators
« Reply #11 on: March 26, 2014, 01:08:39 am »

I tested --/++ a bit, looking good. There is an issue with the C-like for loop though, incrementing/decrementing (like in the code below) doesn't work.

Code: [Select]
`#command("object");int \$i;file \$c;\$c.open("\$console", "w");for (\$i = 10; \$i > 0; \$i--){ \$c.print("%d\n", \$i);}\$c.close();`
I notice that these are only post-decrement/increment operators, not pre-decrement/increment. I rarely use pre-, so I don't really care, but figured it's worth pointing out.

By the way, having alt toggle arc rotate is like a sweet breath of fresh air Many thanks!
Logged

#### Steve

• Hero Member
• Posts: 2124
##### Re: ASL integer bit-wise operators
« Reply #12 on: March 26, 2014, 01:50:48 am »

Hmmm. Pre increment and decrement should be there as well. I only have a couple of test cases (test cases are as much work as the original code !!!) so can you send me yours that don't work correctly?
Logged

#### Raxx

• Hero Member
• Posts: 1482
##### Re: ASL integer bit-wise operators
« Reply #13 on: March 26, 2014, 03:47:26 am »

Here's a few.

Code: [Select]
`#command("object");int \$i;file \$c;\$i = 2;\$c.open("\$console", "w");\$c.print("%d\n", \$i);\$c.print("%d\n", (++\$i)); // Fine in parenthesis\$c.print("%d\n", ++\$i); // Causes Loading Error\$c.print("%d\n", --\$i); // Causes Loading Error++\$i; // Causes Loading Error--\$i; // Causes Loading Error\$c.close();`
Logged

#### Steve

• Hero Member
• Posts: 2124
##### Re: ASL integer bit-wise operators
« Reply #14 on: March 26, 2014, 04:13:43 pm »

Ahhh, foiled by the old Leading Unary Operator trick!

All my tests are of the form "\$x = ++\$y" so I can see the value of the expression as well as the underlying variable.  Anim8or doesn't currently (and apparently never did!) accept expression statements that begin with any unary operator, such as:

-\$i;

I'll fix this and have an update shortly.
Logged
Pages: [1] 2