Académique Documents
Professionnel Documents
Culture Documents
So, we have
Why does it work? Given a value in a certain number system, we want to convert it to a , i.e., we need to find all 's in the expression:
Dividing this by
, we get
, the subsequent is
Multiplying this by
, we get
Note: This method is mostly applicable to conversion of values given in decimal (base 10) system to other systems (base r=2, 8, 16, etc.), simply because we are trained to multiply and divide only in decimal system. In theorey one could use this method to convert a value given in any number system, but one has to know how to multiply and divide in that particular system. More Examples:
Next: Two's Complement Representation Up: arithmetic_html Previous: Number Systems Ruye Wang 2003-10-24
Note:
significant bit (MSB) and the lowest bit (right-most) the least significant bit (LSB). Complement representation is always determined by the number of digits or bits in the representation. Given n bits, is treated as 0 since the 1 in the (n+1)th bit cannot be represented (e.g., , ). Complement of zero: (e.g., Complement of complement: , ).
Sign extension: any number of 0's can be added in front of a number without changing its value. Similarly, any number of 1's can be added in front of the 2's complement representation, without changing its value. Decimal sign extension:
Purpose of complement representation: The 2's complement representation is used to deal with negative numbers and subtractions, because complement is compatible with negation: , , as shown above.
The 1 in the 4th digit is automatically dropped as only Example 2: Carry out binary subtraction in hardware for representing a number. , with
Note that the 7th bit is automatically dropped as only bits are available in hardware. This example shows subtraction can be carried out as an addition of 2's complement of the second number. The question is, how can the 2's complement be easily found?
Three ways to find 2's complement: Given an n-bit binary number found by one of the following equivalent ways: , its 2's complement can be
1. Carry out the subtraction in the definition 2. First find bit-wise complement ( , complement), then add 1 to the LSB Example: ;
) of
; (called 1's
Note that
3. Leave all least significant 0's and the first 1 unchanged, then bit-wise complement the remaining bits. Example:
Note that the least significant three bits 100 are unchanged. Observation on the MSB of 2's complement Assume bits available:
If and
If
, then
i.e., both
and
are represented by
with MSB=1.
If
o
The MSB of
is 1:
Conclusion:
If If
is always 0;
is always 1;
Example:
Next: Fixed-Point Representation Up: arithmetic_html Previous: Number System Conversion Ruye Wang 2003-10-24
Next: Signed-Complement Representation for Fractions Up: arithmetic_html Previous: Two's Complement Representation
Fixed-Point Representation
Signed 2's complement
A fixed point number (an integer) defined as:
If
The MSB can therefore be used as the sign bit. Both cases can be represented by the following:
Note:
Assume there are a fixed number of n bits available in hardware for representing a given value. When , in the expressions above corresponds to a 1 in the (n+1)th bit, which is always ignored in n-bit representation as the (n+1)th bit does not exist. The remaining is in binary form. When , is the definition of 2's complement of .
In this example, the range of values representable by 3-bit signed 2's complement is from 0 to for positive values and from values. In general, we note:
to -1 for negative
When
When
i.e. . The MSB is thus used as the sign-bit to indicate whether the number is positive or negative. The Overall range for Signed-Complement representation is: ;
Any value beyond this range cannot be properly represented as the MSB no longer correctly indicates whether
or
Signed-2's complement representation simplifies the operations when dealing with negative operands and subtractions.
values are represented by signed 2's complement, MSB=1 for to -1), MSB=0 for the values on the
Find value represented in signed-2's complement To find the value of a given number complement format, check the MSB or the sign bit
in signed 2's :
If
If
Example (n=6):
Next: Signed-Complement Representation for Fractions Up: arithmetic_html Previous: Two's Complement Representation Ruye Wang 2003-10-24
If
, but the
Given values is