See two’s complement for the representation of negative integers in many languages. As you can see, -2 is represented by 1111110
; if you invert all those bits you get 0000001
, i.e. a value of 1.
More Related Contents:
- Multiplication of two integers using bitwise operators
- Using bitwise operator to divide by 0 (Simulation of division by 0) [closed]
- Bit manipulation, return 0 if x != 0, or nonzero otherwise
- How to know number is divisible by 3 or any odd number using bitwise operator in python [closed]
- How do you set, clear, and toggle a single bit?
- What are bitwise operators?
- How does the bitwise complement operator (~ tilde) work?
- What is Bit Masking?
- What’s the difference between & and && in JavaScript?
- Real world use cases of bitwise operators [closed]
- Are the results of bitwise operations on signed integers defined?
- How to perform a bitwise operation on floating point numbers
- Convert to binary and keep leading zeros
- Pipe character in Python
- Operator precedence (bitwise ‘&’ lower than ‘==’)
- Where would I use a bitwise operator in JavaScript?
- Efficiently find binary strings with low Hamming distance in large set
- Understanding PHP & (ampersand, bitwise and) operator
- Why does a shift by 0 truncate the decimal?
- Why do we usually use || over |? What is the difference?
- Using bitwise operators for Booleans in C++
- Bitwise Multiply and Add in Java
- Near constant time rotate that does not violate the standards
- The difference between logical shift right, arithmetic shift right, and rotate right
- Decimal to Binary
- How to get the logical right binary shift in python
- A clear, layman’s explanation of the difference between | and || in c#?
- Difference between some operators “|”, “^”, “&”, “&^”. Golang
- Why doesn’t the operator module have a function for logical or?
- How does Python’s bitwise complement operator (~ tilde) work?