In: Computer Science
What is two’s complement representation? What is one’s complement representation? What is sign-magnitude representation? What is unsigned representation? What is BCD?
Two's complement is a mathematical operation on binary numbers, and is an example of a radix complement. It is used in computing as a method of signed number representation.
The two's complement of an N-bit number is defined as its complement with respect to 2N. For instance, for the three-bit number 010, the two's complement is 110, because 010 + 110 = 1000. The two's complement is calculated by inverting the digits and adding one.
The ones' complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa). The ones' complement of the number then behaves like the negative of the original number in some arithmetic operations.
The representation of decimal numbers in everyday business is commonly called the signed-magnitude representation. In this system, a number consists of a magnitude and a symbol which indicates whether the magnitude is positive or negative.
Unsigned binary numbers are, by definition, positive numbers and thus do not require an arithmetic sign. An m-bit unsigned number represents all numbers in the range 0 to 2m − 1. The most significant bit of a binary number is used to represent the sign bit.
Binary coded decimal (BCD) is a system of writing numerals that assigns a four-digit binary code to each digit 0 through 9 in a decimal (base-10) numeral.