Home > Archive > PHP Language > August 2005 > Binary calculations (OR, AND, XOR)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Binary calculations (OR, AND, XOR)
|
|
| Siebie 2005-08-20, 6:56 pm |
| Hey,
Anybody knows a possible way to do binary calculations (OR, AND, XOR).
Anything I type before 'AND' will be outputted, but the AND-word and
anything behind it is ignored. E.g.[color=darkred]
results in 3.
My PHP-version is 4.2.3.
Thanx!
| |
| Kimmo Laine 2005-08-20, 6:56 pm |
| "Siebie" <ceesboofUNSPAM@hotmail.com> kirjoitti
viestissä:Xns96B8AF5583478Siebie@194.109.133.133...
> Hey,
> Anybody knows a possible way to do binary calculations (OR, AND, XOR).
> Anything I type before 'AND' will be outputted, but the AND-word and
> anything behind it is ignored. E.g.
> results in 3.
>
> My PHP-version is 4.2.3.
Binary calculations are done with the binary (or bitwise) operators & | ^
and ~, >> and <<.
Examples:
echo (1 & 2); // Prints 0, since 0001 AND 0010 equals 0000
echo (1 | 2); // Prints 3, since 0001 OR 0010 equals 0011
echo ~(6 ^ 9) // prints 16, since NOT(0110 XOR 1001) equals !0000 equals
1111...
Etc... I just pulled the binary numbers from my hat, and my boolean math is
rusty, so errors may occur, but you get the point... And I assume this was
what you were looking for. See the manual on bitwise operators for more.
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <eternal.erectionN0@5P4Mgmail.com>
| |
| Siebie 2005-08-20, 6:56 pm |
| "Kimmo Laine" <eternal.erectionN0.5P@Mgmail.com> wrote in
news:de7ijr$8vq$1@phys-news1.kolumbus.fi:
> Binary calculations are done with the binary (or bitwise) operators &
> | ^ and ~, >> and <<.
>
> Examples:
>
> echo (1 & 2); // Prints 0, since 0001 AND 0010 equals 0000
> echo (1 | 2); // Prints 3, since 0001 OR 0010 equals 0011
> echo ~(6 ^ 9) // prints 16, since NOT(0110 XOR 1001) equals !0000
> equals 1111...
>
> Etc... I just pulled the binary numbers from my hat, and my boolean
> math is rusty, so errors may occur, but you get the point... And I
> assume this was what you were looking for. See the manual on bitwise
> operators for more.
>
This is exact what I was looking for!
Thanx!
|
|
|
|
|