The 2's complement of a number in n bits is that number whenadded to the original number results in 0 in n bits.It is used to represent negative numbers so that with n bits youhave 2ⁿ⁻¹ each of positive and negative numbers - the top bit isused to specify if the number is negative and if set, the number isstored in 2's complement of the positive number. As a result ofthis, when adding or subtracting positive and negative numbers,there is no need to worry about the sign as it is handledautomatically.To convert a binary number to its 2's complement invert all thebits and add 1 (this is the same as subtracting it from 2 to thepower of one more than the number of bits used to store thenumber)eg in 8 bits, the 2's complement of 42 (0x2A = 0010 1010)is:Invert all the bits: 0010 1010 → 1101 0101add 1: 1101 0101 + 1 = 1101 0110 (0xD6)→ the 2's complement of 42 in 8 bits is 214 (= -42)Note: 42 + 214 = 256 = 1 0000 0000 in binary which has thebottom 8 bits 0.When doing arithmetic with signed numbers, there is usually anoverflow flag (V) in the processor which is set if the operationresults in a carry from the top-1 bit to the top bit.eg in 8 bits when using signed numbers 42 (0010 1010) + 100(0110 0100) = 142 (1000 1110) but as it has the top bit set itrepresents a negative number (142: 1000 1110 → 0111 0001 + 1 = 01110010 = -114) - to indicate that the number (could) represent anegative number not a positive number the processor may set theoverflow flag.The maximum positive number in 8 bits is 127 (0111 1111), themaximum negative number is 1000 0000 → 0111 1111 + 1 = 1000 0000 =-128; ie the range of possible numbers when using 8 bits torepresent a signed number is -128 to +127