HomePagev2 Forums Python Discussions Logical Negation in python

• # Logical Negation in python

• ### Karri Bindu Madhavi

Member
September 25, 2020 at 1:13 pm

logical Negation in python:

~ –>binary ones compliment –> x=-(x+1)
>> –>binary right shift —> digit>>no.of places to shift (in this process,it lost the last two digits)

^ —>binary xor –>if the two inputs are same,it returns ‘0’ or else it returns ‘1’.

process:

formulae=1>>((~x>>1)^~x)

step1: lets take a=~x>>1,do the operation as per the operators conditions

step2: Then after completing this operation,it gives some value and the formulae will be turned as 1>>(a^~x)

step3: Take b=a^~x,do the operation as per the operators conditions given above and this formulae is turned to be 1>>b

step4: After completing this,we able to get a logical negation

example:

`x=5`
`n=1>>((~x>>1)^~x)`

`~x>>1=~5>>1=-(5+1)>>1=-6>>1=1110>>1=11=3`

`n=1>>(3^~5)`

`11^~5=3^-6=1`

n=1>>1=010(in binary form)(lost two bits)=0

n=0

• ### Gnana Divya

Member
October 10, 2020 at 3:22 pm

Good Explanation, with step by step process (Precedence of bitwise of operators).

• ### Karri Bindu Madhavi

Member
October 12, 2020 at 11:56 am

Thank you