Check whether there is need to flip root or not
$ flip = true ; while ( $ remaining > 1 ) { if ( $ remaining & 1 ) { $ flip = ! $ flip ; } $ remaining = $ remaining >> 1 ; } if ( $ flip ) { echo ! $ root . " STRNEWLINE " ; } else { echo $ root . " STRNEWLINE " ; } }