Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Pages: [1] 2

Author Topic: ASL integer bit-wise operators  (Read 4351 times)

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
ASL integer bit-wise operators
« on: March 05, 2014, 10: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 27, 2014, 03:17:51 am by Steve »
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: ASL integer bit-wise operators
« Reply #1 on: March 15, 2014, 03:09:09 pm »

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

  • Full Member
  • ***
  • Posts: 248
    • View Profile
Re: ASL integer bit-wise operators
« Reply #2 on: March 15, 2014, 05: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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: ASL integer bit-wise operators
« Reply #3 on: March 15, 2014, 09: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. [edit]Scratch that
« Last Edit: March 15, 2014, 11:47:12 pm by Raxx »
Logged

Claude

  • Full Member
  • ***
  • Posts: 248
    • View Profile
Re: ASL integer bit-wise operators
« Reply #4 on: March 15, 2014, 10:34:37 pm »

How about something like this:
return $int  ^  0xffffffff;

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

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: ASL integer bit-wise operators
« Reply #5 on: March 15, 2014, 11: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

  • Full Member
  • ***
  • Posts: 248
    • View Profile
Re: ASL integer bit-wise operators
« Reply #6 on: March 16, 2014, 12:55:45 am »

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.
http://en.wikipedia.org/wiki/Hexadecimal

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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: ASL integer bit-wise operators
« Reply #7 on: March 16, 2014, 01:38:46 am »

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

  • Full Member
  • ***
  • Posts: 248
    • View Profile
Re: ASL integer bit-wise operators
« Reply #8 on: March 16, 2014, 02:42:13 am »

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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: ASL integer bit-wise operators
« Reply #9 on: March 16, 2014, 08:55:11 pm »

I forgot about ~. I'll add it.

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

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: ASL integer bit-wise operators
« Reply #10 on: March 26, 2014, 01:42:33 am »

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

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: ASL integer bit-wise operators
« Reply #11 on: March 26, 2014, 05: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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: ASL integer bit-wise operators
« Reply #12 on: March 26, 2014, 05: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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: ASL integer bit-wise operators
« Reply #13 on: March 26, 2014, 07: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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: ASL integer bit-wise operators
« Reply #14 on: March 26, 2014, 08: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