===============================================================
Bitwise Complement Operator ( ~ )
===============================================================
=>Syntax: ~Value
=>The Functionality of Bitwise Complement Operator (~) is that "To Invert the
Bits".
=>Inverting the Bits Process is nothing but 1 becomes 0 and 0 becomes 1.
=>The Formula for Bitwise Complement Operator(~) is -(Value+1)
~Value = - (Value+1)
=>In Computer Science, In Programming Lang, All the Negative Numbers stored in Main
Memory in the form of 2's Complement of the given Number.
=> 2's Complement of Any Number = 1 's Complement +1
=>1 's Complement = 1 becomes 0 and 0 becomes 1
=>Binary Addition Rules
a) 0 + 0 = 0 b) 1 + 0 = 1 c) 0 + 1=1 d) 1 + 1 = 0
with Carry 1
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
Examples
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
>>> a=10
>>> ~a------------------------ -11
>>> a=123
>>> ~a------------------------ -124
>>> a=-100
>>> ~a-------------------------- 99
>>> a=1.3
>>> ~a---------------------------TypeError: bad operand type for unary ~: 'float'
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
Internal Flow of Bitwise Complement Operator ( ~ )
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
Exanmples:
----------------
>>>a=10--------------------> 0000 1010
>>>~a-----------------------> 1111 0101--------------which is Value of -11
-----------------------------------------------------
PROVE THAT ~10 = -11
-----------------------------------------------------
=>We are taking Couter Opp. of -11 which is 11
=>The Binary Form of 11 = 0000 1011
=>1 's Complement of 11= 1111 0100
=>2' 's Complement of 11= 1's Complement of 11+1
1111 0100
0000 0001 (Binary Addition)
-------------------------
1111 0101
-------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
Internal Flow of Bitwise Complement Operator ( ~ )
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
Exanmples:
----------------
>>>a=15--------------------> 0000 1111
>>>~a-----------------------> 1111 0000--------------which is Value of -16
-----------------------------------------------------
PROVE THAT ~15 = -16
-----------------------------------------------------
=>We are taking Couter Opp. of -16 which is 16
=>The Binary Form of 16 = 0001 0000
=>1 's Complement of 16= 1110 1111
=>2' 's Complement of 16= 1's Complement of 16+1
1110 1111
0000 0001
----------------------------
1111 0000 ------Which is 2's Complement
of 16 ( ie. -16)
----------------------------
==================================================x================================
===============