You are on page 1of 17

# Next: Two's Complement Representation Up: arithmetic_html Previous: Number Systems

So, we have

## A systematic method for number conversion

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

## previous quotient by remainders.

, the subsequent is

## The value of the fraction part of

Multiplying this by

, we get

## can be found as the integer part of the products.

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:

## Binary-Coded-Decimal (BCD) Numbers Example:

Next: Two's Complement Representation Up: arithmetic_html Previous: Number Systems Ruye Wang 2003-10-24

o

o

Note:

## of an n-bit number is called the most

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:

## Binary 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.

## Example 1: Carry out decimal subtraction using digits.

The 1 in the 4th digit is automatically dropped as only Example 2: Carry out binary subtraction in hardware for representing a number. , with

## digits are available. bits available

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

## , i.e., bit-wise complement.

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

## , i.e., both with MSB=0.

If

, then

i.e., both

and

are represented by

with MSB=1.

If
o

The MSB of

is 1:

Conclusion:

If If

## , the MSB of , the MSB of

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

## If , it is represented by 2's complement of its magnitude MSB must be 1.

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 .

## Range of integer values representable Example: , , ,

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

## bits represent the magnitude in the range

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.

## When these the

values are represented by signed 2's complement, MSB=1 for to -1), MSB=0 for the values on the

## , the range of values representable is from -16

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

## Both cases can be represented by this formular:

Example (n=6):

Next: Signed-Complement Representation for Fractions Up: arithmetic_html Previous: Two's Complement Representation Ruye Wang 2003-10-24

## Signed-Complement Representation for Fractions

Assuming there are n bits available, and a fraction can be represented by assuming the decimal point to be between the two most significant bits and . And the signed-complement representation of a fraction is the same as that of the integers:

If

, but the

Given values is