Updates

It's been about a month since I have made my last post and I just felt like blogging what I've been doing.

As you may already know I have been training myself for a math competition known as the AMC 10 and it was all fun until recently. I am starting to get bored doing math problems all day. I feel that my passion is more for programming than for math. I still love math, I'm just a bit sick of it . Well anyways, I decided to come back to BYOND but I still won't be as active as before due to the fact that I am more occupied with high school. (For those of you that don't know, I am new to high school.)

The following things are things I plan to accomplish over the next few months or so:
-Revive my Megaman project and do a recode (once again).
-Make a Regex library after I get more experienced in using regexes.
-Get a bit more involved with the community.
-Get control over my obsession with programming. (When I am committed to a game, I usually do nothing more than work on it and I start focusing less on school.)

Posted by Kakashi24142 on Monday, September 15, 2008 08:10PM - 8 comments / Members say: yea +0, nay -0

Bye BYOND! (Also looking for Programmer)

Well these days I hardly find any free time so I will be unable to program for a while. But I can find time to program small tasks once in a while, so if any needs me to program something small then I would have no problem with that. But I cannot program large projects. So far, the only project that will suffer due to my absence will be Megaman: NaviWars. (The rest of the projects have other programmers available that can handle it.)

So if anyone is wishing to continue on NaviWars, I seriously recommend recoding the source to it (it's very yucky, but it does make all the released sources look like crap). I would recommend using some parts of the source as a model, but the rest I recommend re-thinking on your own. So if anyone is interested in continuing NaviWars, please contact me at kakashi24142@hotmail.com (MSN). If you are a programmer that I've never heard of before, I require a code sample for verification and if you aren't, then I'll immediately send the source.

If you all must know what is suddenly taking up my time, it's this: I'm training for next year's AMC 10(American Mathematics Competition) to get a score to be invited to take the AIME (American Invitational Mathematics Exam) and so on. (And if you must know why I am devoting time to these contests, it's because I want to get into MIT and people at MIT look at AIME scores as I've heard.)

Posted by Kakashi24142 on Tuesday, August 05, 2008 06:24PM - 8 comments / Members say: yea +0, nay -0
(Edited on Tuesday, August 05, 2008 06:40PM)

Math=Memorizing Formulas?

If you've thought that that's what Math really is all your life, you are obviously not going to get far. I've thought about math like that since I started learning algebra, but due to some company known as Art of Problem Solving Inc., I finally understand what math really is about. It's about understanding each and every part of an equation. It's know what the equation means. I'd have to say that my entire opinion about math changed once I visited this site. If you are a person who thinks they've mastered algebra, you might want to check this out to find out how much you really don't know. (Trust me, I thought I knew everything until I found that site.)

Posted by Kakashi24142 on Monday, July 28, 2008 10:32AM - 3 comments / Members say: yea +0, nay -0

Java Guild?

Poll: Would it be a good idea if I made this the BYOND Java Guild?

Yes 44% (12)
No 18% (5)
Maybe 37% (10)

Login to vote.

Well I'm learning Java at the moment and I'm the the mood to write a few guides on making Java applets for DM programmers. I will also have a few others that go through the basics of Java. It would also be nice to have people who are more experienced than me to post some guides too. I wasn't sure if it was a good idea or not so I decided to make a poll.

Posted by Kakashi24142 on Friday, July 25, 2008 09:00AM - 4 comments / Members say: yea +0, nay -0

Kakashi's Article #1: Bitwise Operators


Bitwise Operators


In this article, I will explain a little about each bitwise operator, show a few examples of the actual process, and then show these operators in action in Chapter 4. It is meant to be very simple and easy to understand, so if you are a fairly decent programmer and you have trouble understanding, let me know so I can ease off on the vocabulary and possibly add more detail on the parts that are hard to understand.

|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

-----------------------
Table of Contents
-----------------------

0. Introduction & Background
1. Bitwise OR, AND, and XOR
1.1 - Bitwise OR (|)
1.2 - Bitwise AND (&)
1.3 - Bitwise XOR (^)
2. Bitwise NOT
3. Bitwise Shifts
3.1 - Left Shift
3.2 - Right Shit
4. Putting It All Together
5. Credits
*Chapter 4 has 3 sections, but they are not listed.



|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

0. Introduction & Background
Now you may be asking your self why you're reading this and why you should care about this. If you are, then the reason why bitwise operators are so important is due to the sheer fact that they operate much faster than decimal arithmetic operators (like +,-, /,*, etc.). They also shorten the amount of code you use and will prevent you from creating unnecessary variables. (Go ahead and take a glance at Chapter 4 if you want to see what you can do at the bit level.) The rest of this chapter just gives you some slight background knowledge on bits and the base 2 number system, so if you are not interested, you may skip ahead to Chapter 1.

First of all, binary is a number system of the base 2 (which means it only has two numbers, 0 and 1). It is used in computers and stores data for computers. A "bit" is a binary digit that is the fundamental unit of data storage in computers. If a bit is 1, it is referred to as "on," and if a bit is 0, it is referred to "off." Computers run on structures called bytes (groups of 8 bits). BYOND's limit in binary operation is 2 bytes (16 bits). Now, it normally isn't necessary to work at the level of 1's and 0's unless you are aiming for increasing speed in calculation, hence why the square root function in C++ happens to use the << operator. The calculator you use every time you go to math class probably runs on bits (at least the one you use in your computer). You will read more about this in Chapter 3.

Now it's time you learned how to convert binary to decimal (since you'll need it if you're going to program some systems that run off of certain binary numbers, see Section 4.3).

Basically, you take any binary number and start from the right most digit and multiply it by 2^0, then you multiply the digit to the left of that by 2^1, then you multiply the digit after that by 2^2 and so on. You add up all those results to get the decimal conversion of the binary number.

Examples:
1=1*2^0=1*1=1
10=0*2^0+1*2^1=2+0=2
1010=0*2^0+1*2^1+0*2^2+1*2^3=0+2+0+8=10
1101=1*2^0+0*2^1+1*2^2+1*2^3=1+0+4+8=13


------------
Extra:
This is for those of you that need a math equation.


-Where n is the number of digits in the binary number
-x0=right most number, x1=2nd right most number, and so on.
------------

Adding 0's to the left end of the binary number doesn't change its value, just like in the decimal number system.

Here are some basic conversions from binary to decimal that are very useful to have memorized:
1      //1
10     //2
11     //3
100    //4
101    //5
110    //6
111    //7
1000   //8

You can also tell if a number is a power of 2 if it starts with a 1 and has no other 1's in it.
1        //1
10       //2
100      //4
1000     //8
10000    //16

And as a side note, I might mention a "nibble" and that's a group of 4 bits.

If you didn't know the values of the direction flags in DM, here you go:
NORTH=1
SOUTH=2
EAST=4
WEST=8


///////////////////////////////////////////////////////////////
EXTRA#1:

You can directly convert from binary to hexadecimal (a number system of the base 16).

Let me quickly give you some background on hexadecimal. The hexadecimal system has 16 characters: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

You can convert from hexadecimal to decimal exactly like how you would convert from binary to decimal, except you multiply by the powers of 16 instead of the powers of 2. When multiplying the letters, plug in the following values instead of actually multiplying by the letters:
A=10
B=11
C=12
D=13
E=14
F=15

Here are a few examples:
0x9CF=(15)*16^0+(12)*16^1+9*16^2=15+192+2304=2,511
0x999=9*1+9*16+9*256=9+144+2304=2457


Now onto the conversion. When you have a binary number, group it into groups of 4 like so.
//100010001000 - binary number
//1000 1000 1000 - split into groups

Now you convert each set into decimal.
//8 8 8

Those are your digits for the hexadecimal number!
Result: 0x888 (The 0x is to distinguish between number systems. If we just had 888, we'll think it's the decimal number 888.)

Another Example:
1101 1111 1000 
13   15   8

Remember that D=13 and F=15.
Result: 0xDF8

EXTRA#2:

Similarly, you can also quickly convert from binary to octal (base 8 number system that has numbers from 0-7).

(Converting from any base n to decimal is easy, you just multiply each digit of that base n number with powers of n starting from 0 at the right-most digit. So you would multiply by powers of 8 to convert from octal to decimal.)

Instead of grouping into 4, you group into 3.
//100100101 - binary number
//100 100 101 - split up into groups of 3
//4   2   5   - converted to decimal

Result: 0425 (Octal, there is a 0 in front of the number to show that it's octal, removing the zero will do no harm other than confuse the person looking at it, since they'll think it's decimal.)

Oh and if you didn't notice, there's a reason with you group bits into 4's for converting to hexadecimal and into 3's for converting into octal. With groups of 4 bits, the maximum number you can get is 15 (1111), similarly, the maximum number you can get in 3 bits is 7 (111).

If you want to know anymore about these two number systems, I suggest you search Google.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I think that's enough background info to get you started on this article. If I talk about something later on that I forgot to explain about in this section, please let me know and I'll add more to this section.

|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

1. Bitwise OR, AND, and XOR
These operators are the most commonly used bitwise operators. I group all of these under one section due to the fact that they all behave similarly with minor differences. All three of these operators are binary operators which means they require two operands. Operands are numbers (sometimes objects) that are subject to a certain operation, like in A + B, A and B are the operands.

1.1 Bitwise OR (|)
Bitwise OR, represented by a pipe (|) is often used to add a flag into a field. It compares the two corresponding bits and if either one of the bits is 1, the resultant bit will be 1.

Example:
001      //1. In DM, the constant NORTH is equivalent to 1.
100  |   //4. In DM, the constant WEST is equivalent to 4.
-----------
101     //5. In DM, the constant NORTHWEST is equivalent to 5.

As you might notice, doing NORTH | WEST gives you NORTHWEST. Is that a coincidence? This will be discussed more in Chapter 4. (It appears like Chapter 4 is going to be the exciting chapter, doesn't it?)

var/a=1
var/b=2
a |= b   //same as doing a=a|b
//that would give you 3


Interesting Properties:
-ORing any number by itself will give you that number. (a|a=a) (Based on this property, can you think of an advantage?)
-ORing any number by 0 will give you that number. (a|0=a)
-The Bitwise OR operation is commutative. (i.e. a|b=b|a)

1.2 Bitwise AND (&)
Bitwise AND, represented by a single ampersand (&) is often used to check if a flag is turned on in a field and is used to remove flags from a bit field. It compares two corresponding bits and if they are both 1, the resultant bit will be 1. Otherwise, the resultant bit will be 0.

Example:
111000      //56
101010 &  //42
------------
101000      //40


var/a=3
var/b=2
a &= b //you will hardly ever see this done. You will usually see it in an if statement.
//a will be 2


Interesting Properties:
-ANDing any number by itself will give you that number. (a&a=a)
-ANDing any number by 0 will give 0. (a&0=0)
-The Bitwise AND operation is commutative. (i.e. a&b=b&a)

1.3 Bitwise XOR (^)
Bitwise XOR, represented by a caret (^), is often used to toggle bits (this will be explain in detail later on). I will repeat this again even though you may have heard it several times in other tutorials/guides: ^ is NOT used for exponents in DM, ** is. It compares two corresponding bits and if they are different, the resultant bit will be 1. If the bits are the same, then it will be 0.
1010      //6
0100 ^   //4
---------
1110      //14

Interesting Properties:
-XORing a number by a binary number that only contains 1's will toggle all the bits (and thus acts like the Bitwise NOT (~)).
-When XORing a number that contains 1's, all the corresponding bits to the 1's will be toggled (i.e. 1 will become 0 and 0 will become 1).
-XORing can be also be used to turn on/off flags from a bit field.

And that concludes Chapter 1. If you want to get motivated to finish this article, take a look at Chapter 4. (After referring you to Chapter 4 so many times, it makes it seems like there is some deep power lying within it.)

1.i A Closer Look(Incomplete)
(If you're wondering, the reason I chose i is because this section really doesn't exist, unless you want it to. Basically, if you think you've got a fairly good understanding of AND, OR, amd XOR, this section won't be of much use. This is in comparison to i, the imaginary number in algebra.)

Now I'm going to explain in depth about each operator and explain how they work with more examples.

Let's start with the Bitwise OR. I'll prove all the "interesting" properties that I explained about before.

1.) I said that when a number is ORed with 0, you get that number.
11011
00000 |
--------
11011 

As you can see ORing a bit with 0 "preserves" the bit. (It keeps it)

2.) I said that a number ORed with itself, you'll get itself.
110110
110110 |
--------
110110 

As you can see, you got that number again. The reason that this will be useful is when you have a bit field, and say you ORed 2 with it, if you OR 2 with it again, you'll still get the same number. Which is another reason why bit flags are useful. Since if you turn a flag that's already on, nothing will happen that will screw up the bit field.

3.) What happens when you OR a bit with a bit that is 1?
11010101
11111111 |
----------
11111111

As you can see, the bits that are off will turn on, and the bits that are on will stay on. (Also, if you only want to turn on one bit, you don't need to OR with all those 1's. Just makes sure the bit you're ORing with has a 1 corresponding to the bit you want to turn on.)


As for the commutative properties for all the operators, I'll let you prove those yourself.

I will work on this section when I get time.


|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

2. Bitwise NOT
The reason why this operator gets its own chapter is due to the fact that it's the only bitwise unary operator (an operator that only has one operand, similar to ++ and --).

The Bitwise NOT operator, represented by a tilde (~), inverts all the bits (it turns all the bits that are 1's to 0's and 0's to 1's, similar to how XOR can work). The only difference between the Bitwise NOT and Bitwise XOR in their functionality of inverting bits is the fact that a tilde inverts ALL the bits no matter what and XOR only inverts the bits you want inverted, based on the number you use XOR with.

Example:
~0000000000001001=   //Bitwise NOT of 9 
 1111111111110110    // 65,526

The reason I included the "invisible" zeros is because they are also inverted. If you forgot about the zeros, then you would have 6 as a result (which is incorrect). And if you're wondering why there are only 16 digits, either read the DM Reference or read the part in Chapter 0 that you missed.

Interesting Properties:
world<<(~0)

-Doing the above would give you the maximum number bits can arrange (65,535). (Oh and doesn't it make you wonder why the limits for a lot of things is 65,535? If so, it all just comes down to the limitations on bit fields.)
-When used in combination with &, it can be used to turn off a flag.
var/a=1|2 //3
a &= ~2  //a would now equal 1 


|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

3. Bitwise Shifts
The Bitwise shift operators shift the bits over, replacing all the newly created spots with 0's and keeping the old ones. If a bit gets shifted out of range (16 bits is the range in DM), it will be truncated (cut off). Shift operators can be used for many things, you just need to think of a scenario in which it would be useful. (You can find such things in Chapter 4.)

3.1 Bitwise Left Shift
Bitwise Left Shift, represented by <<, simply shifts a binary number n times to the right.
(The form is a << n.)

Example:
(10<<2)=1000 
(10<<4)=100000

Note that 0's are added as it moves to the left.

Interesting Properties:
-It can be used to compute a power of 2 faster than with * or **. (1 << 1 = 1*2^1, 1 << 2 = 1*2^2)
-It it used to compute the square root of a number. (Not sure if this is true for DM.)
-It can allow you create random binary numbers on the fly.
var/i=1
var/bin_num=0
while(i)
    bin_num |= prob(50)? 1 : 0 //50% chance of adding a 1 or 0
    bin_num <<= 1                   //Shift it over by one
    if(prob(rand()*100))break  //break the loop at the probability of a random chance
    //Note: rand() with no arguments will return a random number between 0 and 1 (it will be a rational number).


3.2 Bitwise Right Shift
Bitwise Right Shift, represented by >>, shifts all the bits to the right by n times. It is equivalent to the division by a power of 2 (the opposite of Bitwise Left Shift which multiplies by a power of 2).
(The format of usage is a << n, where n in the number of times you want to shift a by.)

Example:
(10>>2)=0 
(10000>>4)=1

Interesting Properties:
-None that I can think of off the top of my head.

|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

4. Putting It All Together
The chapter you've been waiting for the entire time span of reading this article has arrived! In this chapter, we will be discussing all the various uses of bitwise operations in everyday programming. I didn't anchor the sections in this chapter so that everyone can be kept in suspense on what would be coming up. So here it goes! Each section name reveals the application.

4.1 The Exercise Game
Now you may be thinking, what are flags and why should I care about them? Just keep your pants on and I'll explain. Flags are just numbers that can be added on or removed from a bit field. Let's say you have a game where you exercise. You can either do pushups, pull-ups, or curl-ups. You can't do all of them at the same time though and there are a few exceptions. You can do curl-ups when you do pushups and you can do pull-ups when you do curl-ups. (I know that's very odd, but bear with me, it'll help you understand.) A normal programmer would do the following to figure out what exercise a person is doing.

mob/var
    push_ups=FALSE
    curl_ups=FALSE
    pull_ups=FALSE


Then the programmer would make an exercise variable TRUE when the person is doing that exercise. There is a much simpler way of doing this using bit flags.

#define NONE           0 //0
#define PUSH_UPS   1 //1
#define PULL_UPS   2 //10
#define CURL_UPS  4 //100
mob/var/exercise=NONE


You may notice that the constants are all powers of 2, and there's a reason for that. The binary system lives off of the base 2 so in order for flags to be removed and added properly to get the desired result, you must have flags be a power of base 2. (See what happens when you try to use the OR operation with a number that is not a power of 2, and then try to remove that number.)

If you are familiar with defining constants using #define and using var/const, you may skip the following paragraph.

If you are not familiar with using #define, I'll quickly explain.
The syntax (format) is #define macro_name macro_value
-macro_name should be replaced with the name you want to have for the constant
-macro_value should be changed to the value of that macro. (Note that the macro_value can only be a text string or a number.)
You could also define a constant like so:
var/const/some_constant=constant_value
//some_constant should be the name of the constant
//constant_value should be the value of that constant

The difference between constants created using #define and constants created using variables is that constants defined using #define will be replaced with their value at compile-time, so no unnecessary variables are created. Thus, #define is a better choice.

Continuing on with the exercise game, how would you add one of the flags I just defined? You would do it using |= and to remove flags you would use &=~. The following will be a code snippet of what the simple exercise game will be like. I would encourage you to predict how it will look, and then take a look at it so you get some practice. I will repeat the conditions to the game as I stated before:

"You can either do pushups, pull-ups, or curl-ups. You can't do all of them at the same time though and there are a few exceptions. You can do curl-ups when you do pushups and you can do pull-ups when you do curl-ups." And to clarify it, if you try to do curl-ups when you do pushups, you will stop doing pushups and then do curl-ups, rather than the curl-ups verb not doing anything at all.

#define NONE       0 //0
#define PUSH_UPS   1 //1
#define PULL_UPS   2 //10
#define CURL_UPS   4 //100

mob/var/exercise=NONE

mob/verb
    Push_Ups()
        if(!exercise)
            exercise|=PUSH_UPS  
            
    Curl_Ups()
        //remember that exercise & PUSH_UPS will check if the PUSH_UPS flag has been turned on 
        if(!exercise || (exercise & PUSH_UPS))
            //using & in combination with ~ can removed flags.
            exercise &= ~PUSH_UPS 
            exercise |= CURL_UPS 

    Pull_Ups()
        if(!exercise || (exercise & CURL_UPS))
            exercise &= ~CURL_UPS  
            exercise |= PULL_UPS


I know I forgot to program the verbs to stop doing all those exercises, but remember that this is just an example so you can get an understanding of using | and &. For those of you who want it in simple conditions, you can use the method stated above if you want to know if a person is doing something. Yes, you can define a variable to show that, but you will need to keep track of a lot of variables if the player can do a lot of things. Keep in mind that you can only define 16 different flags for a given bit field due to the limits of BYOND. It's amazing how you can store a lot of information in just one variable without it being a list, isn't it? This wasn't a very good example, but the next one will be.

4.2 Reversing Directions
Let's say that there is a condition in your game where a player gets confused. And in this state, if the player presses right, the mob moves left, and if the player pressed up, the mob moves down, etc. I will introduce how to use a bitwise operator in this situation the same way I did in the previous section - I show you what a normal programmer would do, then I show you what an experienced programmed would do (given that the experienced programmer knows how to use bitwise operators properly). In this example, we will only consider reversing the cardinal directions for the sake of simplicity.

mob/Move(turf/Loc,Dir)
    if(confused)//I know this goes against what I said in the previous section, but that only applies when there are multiple things a player can do. I assume that the player can ONLY get confused in this game.
        switch(Dir)
            if(NORTH)
                Dir=SOUTH
            if(SOUTH)
                Dir=NORTH
            if(EAST)
                Dir=WEST
            if(WEST)
                Dir=EAST
    .=..()

Now that does seem like a lot of code doesn't it? In fact, there is an easier way to do this. And this can be accomplished using the Bitwise XOR (^) operator.
mob/Move(turf/Loc,Dir)
    if(confused)
        Dir ^= (Dir>>2)? 12 : 3
    .=..()

You might notice that I used the Bitwise Right Shift operator and the reason for that is because you need to change the value your use the XOR operation with based on if it's a vertical direction or horizontal direction. (Consult Section 3.2 for more information.) If you notice carefully, 3=(NORTH|SOUTH) and 12=(EAST|WEST). I used the principle of using 1's with the XOR operation to toggle bits for this example. Let's take EAST as an example to be the Dir argument and see what happens in the XOR operation. According to the code, we XOR with 12.

So:
0100   //EAST
1100 ^ //12
---------
1000 //This is WEST

You can evaluate all the other directions by yourself and see what happens. You may be asking yourself, "How did he get that formula out of nowhere?" The easiest way to derive it is to play around with the binary forms and see what you get. It's the same method I used to figure out the properties of the various operators. You also have to take into consideration the operators' functionalities to help you derive these formulas. Now you know how Popisfizzy comes up with all those complicated formulas, which by now should be understandable. (Of course, he's experienced so he can probably get the formulas faster than I can.)

I will now briefly explain about using bitwise operations in daily programming before I continue to the last example. If you use numbers in any way in programming to represent a certain condition or state or if you are using a lot of math, bitwise operators can usually simplify the work for you. The most common uses of them are to simplify programming that deals with using the direction flags (NORTH, SOUTH, EAST, WEST). You can also use it when you are using variables that are boolean (variables that take the value of either 1 or 0). I bid you all good luck with deriving formulas using bitwise operations to simplify your programming, now let's proceed to the final (but interesting) example!

4.3 Bitwise Elemental System
You may have seen my previous blog post on bitwise elemental system (and you should probably be able to understand it now), but this is an alternate method. I planned this out on a long car ride so I hope it's pretty good. This time I won't show the novice programmer's code before the real thing. Also, all the work required for this method is not really necessary, but it used as an example of the use of the Bitwise shift operators.

I will now explain the idea behind this system. This system is only meant for a max of 5 different elements (I'm going to show it for 4).

Each element will be represented in a bit field like so:

FWEA FWEA FWEA
F=Fire
W=Wood/Grass
E=Electric/Thunder
A=Aqua/Water


The first part represents the identity of the element. For example, if it was 1000, the element would be fire, if it was 0100, it would be Wood, etc. The second part represents the identity of the element which the current element is strong against. (Fire is strong against Wood so its second part would be 0100.) And the last part represents the identity of the element that's the current element is weak against. (So for Fire the last part would be 0001 since it's weak against water). Now for implementation:

//I figured out the following conversions using a calculator
#define FIRE  2113 //1000 0100 0001
#define WOOD  1064 //0100 0010 1000
#define ELEC  532  //0010 0001 0100
#define WATER 386  //0001 1000 0010
#define NONE  0 

proc/getIdentity(element)
    return ((element & 3840) >> 8)
proc/getWeakness(element)
    return (element & 15)
proc/getStrength(element)
    return ((element & 240) >> 4)//Retrieves the necessary bits and deletes the rest. 
    
//Sample Code adapting the element system to show how it's used.  
    
mob/var/element=NONE

mob/verb
    setElement()
        element=pick(FIRE,WOOD,ELEC,WATER)
    getDamage(element as num)
        //Make sure the input entered matches the elements showed above,
        //otherwise it won't work properly.
        if(getStrength(src.element) == getIdentity(element))
            //if the strength of your element is equivalent to the element specified
            world<<"You are strong against that element!"
        else if(getWeakness(src.element) == getIdentity(element))
            world<<"You are weak against that element!"
        else
            world<<"You are equally matched against that element!"


I will explain how the three procedures work now, even though they are quite self-explanatory.
getIdentity():
-This procedure will retrieve the identity of the element by using the AND operation with 3840 (1111 0000 0000) and then it gets shifted by 8 (so that the other 0's to the right don't affect its value).
getWeakness():
-This procedure will retrieve the identity of the element that is weak to the specified element by using the AND operation with 15 (1111).
getStrength():
-This procedure retrieves the strength of the element by using the AND operation with 240 (0000 1111 0000) to recieve the necessary bits and then shifts to the right by 4 to remove the unnecessart 0's that will distort it's value.

Well, I hope you understood my article and if you had any problems understanding, please contact me as soon as possible so that I can change this article to make it more easier to understand.

***All constructive comments/suggestions are urged for and appreciated. If you happen to find a grammatical error or improper word usage in this article, please let me know.


|&^>><<|&^>><<|&^>>& lt;<|&^>><<|&^>><<|&^ >><<|&^>><<|&^>><< ;|&^>><<|

5. Credits

I would like to thank the following people:
-Lummox Jr: For his suggestion on adding conversion from binary to hexadecimal and for pointing out mistakes.
-Naokohiro: For pointing out the odd characters that appeared throughout the article.
</<>

Posted by Kakashi24142 on Monday, July 14, 2008 01:34PM - 5 comments / Members say: yea +0, nay -0
(Edited on Wednesday, August 20, 2008 11:19AM)

Kakashi24142

Joined: Apr 05, 07

Home page Email

Anime Fan and Programmer

Blog Calendar

September 2008
Su Mo Tu We Th Fr Sa
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
 
«Aug