00:00
00:00
Newgrounds Background Image Theme

jailander1 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Math - Intermediate

4,747 Views | 19 Replies
New Topic Respond to this Topic

AS: Math - Intermediate 2005-07-03 15:17:09


AS: Main
Basic Math
The Math class in Flash consists of a very large set of operators, for calculating values while running the .swf

I'm going to go over some of the more advanced operators here, bitwise operations.

Basic Boolean Arithmatic Operators

Shift Operations
All numbers on your computer are represented as 0's and 1's more on the actual representation in math advanced. for now we need to know of 2 very quick

and very useful operators << and >> , they are "shift left" and "shift right" , we will use them for ultra fast multiplication and devision by

two, they are over 10 times faster then *2 and /2.

<< (bitwise left shift) is used to shift the bits left, for example
2 which is 10
will become 8 which is 1000
when shifted 2 to the left meaning 8 == 2 << 2;

5 which is 101
will become 10 which is 1010
when shifted 1 to the left, since 10==5 << 1;

all you need to really remmember, that you state the number of times you are multiplying by 2

the usage is as following object1 << object2 shifts object1 object2 locations.
if you want to shorten it and assign object1 = object1 << object2 you may use
object1 <<= object2, this will auto asign it to object 1

>> (bitwise shift right) is used for devision I will not bother explaining it since it does THE EXACT OPPISITE OF OBJECT 1.

remmember, this trick does not work on fractions

Strict Equality

you probebly know that 0 == false in flash, and that null is also the same, and true is equal to one and is equal to many other things, sometimes, knowing it is

equal is not enough, we also want to know it is the same type, for that the "===" operator exists, it checks if the object has the same value and is

the same type

false==0 returns true;
false===0 returns false;

pretty simple, yet very useful

Decreasment and Increasment by 1

to decrease a number called "num" by one all you really have to do is write

num--;

to increase it, you write

num++;

this is pretty handy in for loops, you use it alot in them. now there is an often overlooked difference between num++ and ++num, num++ triggers AFTER the

statement where ++num triggers while it, so for example if num is 7 i=num++ will make i 7 too but i=++num will make i8, num becomes 8 in both cases.

That's all for this time, actual boolean math in Math: Advanced.

Response to AS: Math - Intermediate 2005-10-26 13:45:32


Lol, no replies, that's just sad :(
I think people are getting fed up from your 1337 AS:___ :P

As usual, nice tutorial...


BBS Signature

Response to AS: Math - Intermediate 2005-10-26 13:47:34


At 10/26/05 01:45 PM, -Toast- wrote: Lol, no replies, that's just sad :(
I think people are getting fed up from your 1337 AS:___ :P

As usual, nice tutorial...

it took u 3 and a half month to say that? =)

Response to AS: Math - Intermediate 2005-10-26 13:48:19


Yeah toast get withthe times baby :P

Though when I saw only 1 reply I thought it was a remake or something


- Matt, Rustyarcade.com

Response to AS: Math - Intermediate 2005-10-26 13:51:27


At 10/26/05 01:48 PM, Ninja-Chicken wrote:
Though when I saw only 1 reply I thought it was a remake or something

Nope, it's just that unpopular Inglor again, no one likes him - no one posts here :D


BBS Signature

Response to AS: Math - Intermediate 2005-10-26 14:02:54


I haven't ever read this before, but I just did and I got the << and >> thing.. I want to learn more bitwise mathematics, I really don't understand it.. heh :)

Great tutorial, though there were a lot of linebreaks.. whats up there?


Sup, bitches :)

BBS Signature

Response to AS: Math - Intermediate 2005-10-26 14:21:36


At 10/26/05 01:51 PM, -Toast- wrote:
At 10/26/05 01:48 PM, Ninja-Chicken wrote:
Though when I saw only 1 reply I thought it was a remake or something
Nope, it's just that unpopular Inglor again, no one likes him - no one posts here :D

No its just he writes so many that its hard to reply to all (especially the less useful ones)

The thing I find about inglors tutorials are that they assume you have a certain ammount of knowlage on the subject already and he wants to clarify it which unfortunatly isnt always the case.
Deltas tutorials are almost too in-depth which means its hard to get you're head around but when you do your an expert on the subject


- Matt, Rustyarcade.com

Response to AS: Math - Intermediate 2005-10-26 14:50:11


At 10/26/05 02:02 PM, -liam- wrote: I haven't ever read this before, but I just did and I got the << and >> thing.. I want to learn more bitwise mathematics, I really don't understand it.. heh :)

Great tutorial, though there were a lot of linebreaks.. whats up there?

I never really knew what the << and >> did, but i know how to write binary numbers.

we'll take 4 0's for example, 0000

1000 is 8, 0100 is 4, 0010 is 2, 0001 is 1 (you dont need the 0's before the one)

So it's like a base 2 number system versus our base 10 number system.

1001010101 is 512+64+16+4+1 is 597

Response to AS: Math - Intermediate 2005-10-26 14:55:46


At 10/26/05 01:45 PM, -Toast- wrote: Lol, no replies, that's just sad :(
I think people are getting fed up from your 1337 AS:___ :P

I hardly think it's sad. Not to offend, but these just aren't among the most practical and essential pieces of script, except for increment and decrement, but I think everyone knows those - even Toast). You'd be hard pressed to find a person who was scouting around for a more efficient way to multiply by two. I'm by no means saying that they're useless, but there are a lot fewer ways that they'd be applied around here than - say - a jump script or something.


BBS Signature

Response to AS: Math - Intermediate 2005-10-26 15:04:45


Yeah I learned alot about binary in my electronics class. It goes up in powers of 2.

Lets say you got

1001
8421

so 1001 = 9

Number << X

is moving the binary X ammount in the specified direction (so multiplying by that power of 2)

So

9 = 1001
9 << 2 = 100100

1 0 0 1 0 0
32 16 8 4 2 1

So

100100 = 36

9 << 2 = 36

Which if you work it out

9 X 2 = 18
18 X 2 = 36

)

Just thought id clear that up for the people who didnt knwo

4 << 6 == 4 x 2 x 2 x 2 x 2 x 2 x 2 == 256 == 100000000

)

- Matt, Rustyarcade.com

Response to AS: Math - Intermediate 2005-10-26 15:12:07


At 10/26/05 02:55 PM, NegativeONE wrote:
I hardly think it's sad.

Well, no, but it's funny then no one actually noticed this thread.

Not to offend, but these just aren't among the most practical and essential pieces of script,

I agree, although everything in life can be useful :D

except for increment and decrement, but I think everyone knows those - even Toast).

Why are you implying the word "even", does it mean "even toast(Who is bad at maths)"? :P

You'd be hard pressed to find a person who was scouting around for a more efficient way to multiply by two.

That's true, I don't think I would have ever done that, heh.

I'm by no means saying that they're useless, but there are a lot fewer ways that they'd be applied around here than - say - a jump script or something.

Agreed.


BBS Signature

Response to AS: Math - Intermediate 2005-10-26 15:13:14


Heh I think I just wasted 5 minuits :P


- Matt, Rustyarcade.com

Response to AS: Math - Intermediate 2005-10-26 15:41:05


At 10/26/05 03:12 PM, -Toast- wrote: I agree, although everything in life can be useful :D

Go read the General board for a day and reconsider that, heh.

Why are you implying the word "even", does it mean "even toast(Who is bad at maths)"? :P

B)


BBS Signature

Response to AS: Math - Intermediate 2005-10-26 15:44:59


At 10/26/05 03:41 PM, NegativeONE wrote: Go read the General board for a day and reconsider that, heh.

The general board.. where being banned for spamming is rather random, you never know if a topic is going to be considered spam or not and you are unsure whether your post is contributing to the topic at hand or not. Mainly because you are unsure at what the topic at hand actually IS.


Sup, bitches :)

BBS Signature

Response to AS: Math - Intermediate 2005-10-26 15:50:46


Nice tutorial,
this is helpful for things non-NG realated,like a school project

Response to AS: Math - Intermediate 2005-10-26 16:50:52


Nobody listens to me :P


- Matt, Rustyarcade.com

Response to AS: Math - Intermediate 2005-12-18 15:49:46


this is how you could explain the shift thingy:
x << y = x * (y * 2)
x >> y = x / (y * 2)
i think that would be alot more easy.


|

Response to AS: Math - Intermediate 2005-12-18 15:54:44


At 12/18/05 03:49 PM, mb3 wrote: this is how you could explain the shift thingy:
x << y = x * (y * 2)
x >> y = x / (y * 2)
i think that would be alot more easy.

good makes it clearer but a n00by will look at that and cry

My post explains it in a way even a 5 year old could understand

(toaststill can't)

- Matt, Rustyarcade.com

Response to AS: Math - Intermediate 2006-05-28 17:02:21


I don't undertand that last bit about ++ as opposed to += 1 and stuff.

Response to AS: Math - Intermediate 2006-06-22 16:58:04


At 12/18/05 03:49 PM, mb3 wrote: this is how you could explain the shift thingy:
x << y = x * (y * 2)
x >> y = x / (y * 2)
i think that would be alot more easy.

actually, that is not correct

x << y = x * (2^y)
x >> y = x * (2^-y) or x / (2^y)

and ofcourse, this is very fast, because it deals with integers

so 3 >> 1 = (1.5) 1
5 >> 2 = (2.5) 2 >> 1 = 1