Working: The negative terminal of the battery is gounded and corresponds to the 0 state and the positive (i.e., voltage 5 V in the present case) to the 1 state.
When both A and B are connected to 0, no current passes through the diode and therefore no voltage develops across R and the output is zero.
When input A is connected to zero and B to 1, the diode D2 is forward biased and the current through it is limited by a current limiting resistance. This current causes a 5 V drop across the resistance assuming the diode to be ideal and this gives an output of 5 V or 1. Interchanging A and B to 1 and 0 will still give a 5 V drop across the resistance as D1 will conduct.
When the terminals A and B are connected to 1, then both the diodes D1 and D2 conduct. However, the voltage drop across R cannot exceed 5 V and the output is 1.