public function addOneToBytePreserveCarry($currentByte, &$carry) {
        for( $i = 0; $i < 8; $i++ ){
            $bitMaskValue = pow( 2, $i );
            $mask = chr( $bitMaskValue );
            $filteredBit = $currentByte & $mask;
            if( $carry == 1 && ord( $filteredBit ) == 0 ){
                $currentByte |= $mask;
                $carry = 0;
            }else if($carry == 1 && ord( $filteredBit ) >= 1){
                $flipMask = ~$mask;
                $currentByte &= $flipMask;
                //carry bit remains unchanged
            } 
        }
        return $currentByte;
    }
public function addOneToBytePreserveCarry($currentByte, &$carry) {
        for( $i = 0; $i < 8; $i++ ){
            $bitMaskValue = pow( 2, $i );
            $mask = chr( $bitMaskValue );
            $filteredBit = $currentByte & $mask;
            if( $carry == 1 && ord( $filteredBit ) == 0 ){
                $currentByte |= $mask;
                $carry = 0;
            }else if($carry == 1 && ord( $filteredBit ) >= 1){
                $flipMask = ~$mask;
                $currentByte &= $flipMask;
                //carry bit remains unchanged
            } 
        }
        return $currentByte;
    }
public function addOneToBytePreserveCarry ( $ currentByte , & $ carry ) { for ( $ i = 0 ; $ i < 8 ; $ i ++ ) { $ bitMaskValue = pow ( 2 , $ i ) ; $ mask = chr ( $ bitMaskValue ) ; $ filteredBit = $ currentByte & $ mask ; if ( $ carry == 1 && ord ( $ filteredBit ) == 0 ) { $ currentByte |= $ mask ; $ carry = 0 ; } else if ( $ carry == 1 && ord ( $ filteredBit ) >= 1 ) { $ flipMask = ~ $ mask ; $ currentByte &= $ flipMask ; //carry bit remains unchanged } } return $ currentByte ; }
We add one by inserting the 1 into the first carry bit.

This is public for testing only.

@param type $currentByte
@param type $carry
We add one by inserting the 1 into the first carry bit .