Converting a 32bit number in a proprietary timestamp with PHP
Not being a PHP expert, but messing with bitwise operations a lot, I have some advice for you:

First, the specification for your operations should be embedded with the code as a comment. Having to look up a specification that may or may not be the same as the one you used when programming it, is not useful... and changing between screens/pages to inspect the code vs. the specification is also not much fun. Something like:

// Input data is 4 bytes with following bit-specification:
// Byte0  (least significant)
//     0-5 : minutes
//     6   : reserved
//     7   : valid
// Byte1
//     0-4 : hours
//    ........


This makes it easier to compare/validate your code.

My next suggestion is to shift the data as you pull values off... This way you don't need to do 'brain-mushing' thinking when doing the manipulation.

// get the first 6 bits
$min = $decimal &amp; 63; // 111111 in binary
$decimal = $decimal &gt;&gt; 6; // get rid of those 6 bits,
                          // now we only need to worry about low bits.


Then, the next suggestion is to set up some 'constants' for your masks:

$mask6bits = (1 &lt;&lt; 6) - 1; // 00111111 in binary.


Now, the example above becomes:

// get the first 6 bits
$min = $decimal &amp; mask6bits;
$decimal = $decimal &gt;&gt; 6; // shift off minutes


Then, I recommend you process the fields you don't need, and it helps you keep track of the specification:

// get the first 6 bits
$min = $decimal &amp; mask6bits;
$decimal = $decimal &gt;&gt; 6; // shift off minutes

$decimal = $decimal &gt;&gt; 1; // shift off reserved

$decimal = $decimal &gt;&gt; 1; // shift off valid

$hours = $decimal &amp; mask5bits;
$decimal = $decimal &gt;&gt; 5; // shift off the hours.


Follow the same pattern for the other bits...

This is a relatively concise way to do things, actually, and you only need to keep one 'dimension' (the length of each data value) of the problem in your head, and you can ignore the offset.

This leads to fewer bugs, and better understanding and readability.

I cannot find a definitive reference whether PHP supports a definitive &gt;&gt;= assignment operator. If it does, the lines $decimal = $decimal &gt;&gt; 5 can be replaced with $decimal &gt;&gt;= 5