Unofficial LSL Reference

[[types:integer]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

types:integer [2015-09-22 11:25 SLT]
sei simplify wording of example
types:integer [2015-09-22 17:39 SLT] (current)
sei an -> a
Line 116: Line 116:
 So the final result is the binary number 00000000000000000000000000000001 which is 1 in decimal. Similarly, ''​5|3''​ is 7 (00000000000000000000000000000111 in binary). //XOR// results in 1 when the bits are different, and 0 when they are equal (or put another way, it flips only the bits of the first operand which are 1's in the second operand); therefore ''​5^3''​ is 6 (00000000000000000000000000000110 in binary). So the final result is the binary number 00000000000000000000000000000001 which is 1 in decimal. Similarly, ''​5|3''​ is 7 (00000000000000000000000000000111 in binary). //XOR// results in 1 when the bits are different, and 0 when they are equal (or put another way, it flips only the bits of the first operand which are 1's in the second operand); therefore ''​5^3''​ is 6 (00000000000000000000000000000110 in binary).
  
-The //bitwise NOT// operator is an //unary// operator (one that applies to single numbers, like the minus sign in front of a number does). It uses the symbol $op[~] (tilde) and results in each bit of the number being flipped. For example, ''​~5''​ returns the binary number 11111111111111111111111111111010 which equals the decimal number -6. In arithmetic terms, ''​~n''​ performs the same operation as ''​-1-n'',​ because ''​-1''​ is all ones in binary, and subtracting any binary number from it results in the bits of that number being flipped (e.g. in 4-bit arithmetic, 1111-1010 results in 0101).+The //bitwise NOT// operator is //unary// operator (one that applies to single numbers, like the minus sign in front of a number does). It uses the symbol $op[~] (tilde) and results in each bit of the number being flipped. For example, ''​~5''​ returns the binary number 11111111111111111111111111111010 which equals the decimal number -6. In arithmetic terms, ''​~n''​ performs the same operation as ''​-1-n'',​ because ''​-1''​ is all ones in binary, and subtracting any binary number from it results in the bits of that number being flipped (e.g. in 4-bit arithmetic, 1111-1010 results in 0101).
  
 The operator $op[<<​] takes two integers, and displaces the binary representation of the first number to the left by an amount of bits indicated by the second number, filling the digits inserted on the right with zeros, and making the higher-order bits to be lost. This effectively results in multiplying the first number by 2<​sup>​(second number)</​sup>​. For example, ''​5<<​3''​ returns ''​40'',​ because ''​5<<​3''​ inserts three zeros on the right and discards the ones on the left, resulting in the binary number 00000000000000000000000000101000 which is 40 in decimal; or in other words, it multiplies 5 by 2³, i.e. returns 5 times 8 which is 40. The operator $op[<<​] takes two integers, and displaces the binary representation of the first number to the left by an amount of bits indicated by the second number, filling the digits inserted on the right with zeros, and making the higher-order bits to be lost. This effectively results in multiplying the first number by 2<​sup>​(second number)</​sup>​. For example, ''​5<<​3''​ returns ''​40'',​ because ''​5<<​3''​ inserts three zeros on the right and discards the ones on the left, resulting in the binary number 00000000000000000000000000101000 which is 40 in decimal; or in other words, it multiplies 5 by 2³, i.e. returns 5 times 8 which is 40.