Check whether there is need to flip root or not
Boolean flip = true ; while ( remaining > 1 ) { if ( ( remaining & 1 ) > 0 ) { flip = ! flip ; } remaining = remaining >> 1 ; } if ( flip ) { Console . WriteLine ( ! ( root > 0 ) ) ; } else { Console . WriteLine ( root ) ; } }