![]() |
operators
How do this operators work? I've seen them around, and I've wondered how they work
HTML Code:
Bitwise-Shift left a << banyone can help me with those? AND, what is the fully different beetween "=" and "=="? |
Quote:
|
Shift, Invert and Xor are bit-operators. Graal handles all numbers internally as floating point values, but those operators are still interesting for some purposes. Integer numbers can be represented as fields of 32 bits, the first bit stands for 1, the second for 2, the third for 4, the fourth for 8 etc. Example: 10 is 8 + 2, so the bit representation is 1010 (we start reading from the right, the fields stand for 8421). Invert is inverting the bits, shift is moving the bits to the right or to the left (which is basicly multiplying with 2 or dividing by 2), and xor is combining two bit fields and the bits in the result are set when the bits of the two operands are unequal.
|
Quote:
PHP Code:
Quote:
you can show some examples on how they work? I would love to know those bit-operators, and how to use them properly in a script ^^ |
Quote:
No. foo = bar; would assign the value of bar to foo. You can't assign a value to something in a condition statement. |
Quote:
foo = bar; would assign the value of bar to foo. You can't assign a value to something in a condition statement. Quote:
|
darn, I forgot to mention,
I wanted to know the different beetween doing that in an statement, like PHP Code:
so I decided to post a thread about it, but oh well.. |
Quote:
See: http://forums.graalonline.com/forums...ad.php?t=66825 Basically, (foo = bar) is allowed for people who don't know better at the expense of others. :( |
Thanks Novo :D
Now I just wonder how xor etc.. (first post) works in a script, like I used ages on figure out the a? b : c stuff untill someone said: condition ? true : false, then I understood it I would like to know a explanation on xor and those (again, first post) and again, Thanks Novo :D |
xor is EXCLUSIVELY OR...
PHP Code:
PHP Code:
|
I tested the xor stuff, and I did this:
PHP Code:
PHP Code:
by this it looks like it returns false if they are not the same, and false if they are equal, so..? if this is not right, got an example? |
var1 != var2
1 != 2... So... That would be true. The other part... (var1 || var2) means true || true => true. It works wonders on TRUE and FALSE... But... I think you found a bug? Because, if you check it out... Everything that is not false (0) is true... So it should have both been false ( Theoretically ) But... The problem with my script ( and that of graal ) is it doesn't evaluate var1 and var2 as such. (!var1) != (!var2) should be the RIGHT version... Hrm. As for the echo part... I'd just do: PHP Code:
|
weird..
Quote:
|
Uhhhh xor does not act like you think it does.
PHP Code:
<< PHP Code:
PHP Code:
PHP Code:
|
Quote:
|
In addition, ...
| (or) PHP Code:
PHP Code:
|
Nice, I think I will experiment with those,
I did understand it, but I don't know how you can know what a binary is, like you said 000.......0001 = 1 000.......0010 = 2 000.......0110 = 6 etc.. how do you know that? :O is there an rule or something? Well, thanks Tolnaftate :D |
Yes there's a rule..
It checks like true / false: 32,16,8,4,2,1 Lets say you have the line; 000110 That's like; 0,0,0,1,1,0 The 4 is true, and the 2 is true, you count all the "true" things.. which makes 6. |
hmm,
so like 25, 20, 15, 10, 5 into 0, 0, 1, 1, 1 that would be 30? but how is that if you only got one number? btw, Thanks Contiga :D |
There are 32 bits.
I usually read binary backwards. The bit on the end is 1 (2^0). The second to last is 2 (2^1). The one before that is 4 (2^2). Then 8 (2^3), 16 (2^4), 32 (2^5), ... etc. You multiply the bit (0 or 1) by each of these numbers then add them up. The ones where the bit is 0 will just be 0, so they don't change the number. 000........1010 .............^.^ .............3..1 2^3 + 2^1 = 10, thus it represents 10. |
| All times are GMT +2. The time now is 03:20 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.