[Typo3-dev] bit-operations

Jan-Hendrik Heuing [netfielders] jh at netfielders.de
Wed Oct 8 02:31:48 CEST 2003


Looks very well, but does actualy not work. We tried to figure out what you
are actualy doing :) Looks a bit like bit-shifting-around, but we didn't get
it properly, at least we didn't get it to work. If you have the correct way
of doing it, we'd like to know...

This works anyway:
   $binstring = strrev(str_pad(decbin ($dec),8,"0",STR_PAD_LEFT));
   $bitarray = explode(":",chunk_split($binstring, 1, ":"));
But yours looks much better anyway. (I found that snipped on php.net, I've
been using a function which has ben a little larger than that....)

jh


"Kasper Skårhøj" <kasper at typo3.com> schrieb im Newsbeitrag
news:mailman.1051894263.28907.typo3-dev at lists.netfielders.de...
>The only way I can thing of now: Check every dingle digit in binary and do
>things. Looks rather complicate, I guess there should be function, as this
>is a comming problem.

I don't fully get it.

If you have an integer, "11" and you want to see if bit number 3 is set (dec
= 8) then you do:

$int = 11;

if ($int & pow(2,3)) {
...
}

(If I remember correctly)

The number "3" represents you bit number and the comparison is a bitwise
"AND" operation.
- kasper

---------------------
Q: So who is going to drive TYPO3 ahead?
A: The man in the mirror!








More information about the TYPO3-dev mailing list