Two’s complement is a system that allows a binary number to be reversibly converted into a number with an equivalent value but negative.
- Find the positive binary value for the negative number you are looking to represent.
- Add a leading
0to the front of the number to show it is positive.
- Invert each bit in the number
- Add 1 to the number
Denary number: 10 Binary Equivalent: 1010
A fairly rudimentary representation of this algorithmically is as follows. It isn’t perfect and has flaws - but it does the job a decent chunk of the time. Issues are included in the comments.