Docsity

Binary and Decimal Number Representations: Complements, Overflow, Real Numbers, IEEE 754 -, Study notes of Computer Science

Partial preview of the text

Download Binary and Decimal Number Representations: Complements, Overflow, Real Numbers, IEEE 754 - and more Study notes Computer Science in PDF only on Docsity!

CSCE 210:

Computer Hardware

Foundations

Chin-Tser Huang

[email protected]

University of South Carolina

Chapter 5: Representing

Numerical Data

9/15/2009 4

Unsigned Numbers:

Integers

Unsigned whole number or integer

Direct binary equivalent of decimal integer

Decimal Binary BCD (Binary-Coded Decimal) 68 = 0100 0100 = 0110 1000 = 2^6 + 2^2 = 64 + 4 = 68 = 2^2 + 2^1 = 6 23 = 8 99 (largest 8-bit BCD) = 0110 0011 = 1001 1001 = 2^6 + 2^5 + 2^1 + 2^0 = = 64 + 32 + 2 + 1 = 99 = 2^3 + 2^0 23 + 2^0 = 9 9 255 (largest 8-bit binary) = 1111 1111 = 0010 0101 0101 = 2 8

  • 1 = 255 = 2 1 2 2 + 2 0 2 2 + 2 0 = 2 5 5  (^) 4 bits: 0 to 9  (^) 16 bits: 0 to 9,  (^) 8 bits: 0 to 99  (^) 32 bits: 0 to 99,999,

Value Range: Binary vs.

BCD

BCD range of values < conventional binary

representation

Binary: 4 bits can hold 16 different values (0 to 15)

 BCD: 4 bits can hold only 10 different values (0 to 9)

No. of Bits BCD Range Binary Range 4 0-9 1 digit 0-15 1+ digit 8 0-99 2 digits 0-255 2+ digits 12 0-999 3 digits 0-4,095 3+ digits 16 0-9,999 4 digits 0-65,535 4+ digits 20 0-99,999 5 digits 0-1 million 6 digits 24 0-999,999 6 digits 0-16 million 7+ digits 32 0-99,999,999 8 digits 0-4 billion 9+ digits 64 0-(10^16 -1) 16 digits 0-16 quintillion 19+ digits

Simple BCD Multiplication

Packed Decimal Format

IBM System 370/390 and Compaq Alpha

Supported by business-oriented

languages like COBOL

Sign-and-Magnitude

Use left-most bit for sign

 0 = plus; 1 = minus

Total range of integers the same

Half of integers positive; half negative

Magnitude of largest integer half as large

Example using 8 bits:

Unsigned: 1111 1111 = +

Signed: 0111 1111 = +

 Note: 2 values for 0:

+0 (0000 0000) and -0 (1000 0000)

Difficult Calculation

Algorithms

 (^) Sign-and-magnitude algorithms complex and difficult to implement in hardware  (^) Must test for 2 values of 0  (^) Useful with BCD  (^) Order of signed number and carry/borrow makes a difference  (^) Example: Decimal addition algorithm

Addition:

2 Positive Numbers

Addition:

1 Signed Number

  • 2
  • 4
  • 4

9/15/2009 13

9’s Decimal Complement

 (^) Taking the complement : subtracting a value from a standard basis value  (^) Decimal (base 10) system diminished radix complement  (^) Radix minus 1 = 10 – 1 9 as the basis  (^) 3-digit example: base value = 999  (^) Range of possible values 0 to 999 arbitrarily split at 500 Numbers Negative Positive Representation method Complement Number itself Range of decimal numbers -499 -000 +0 499 Calculation 999 minus number none Representation example 500 999 0 499 999 – 499

9’s Decimal Complement

Necessary to specify number of digits or

word size

Example: representation of 3-digit number

First digit = 0 through 4 positive number

First digit = 5 through 9 negative number

Conversion to sign-and-magnitude number

for 9’s complement

321 remains 321

521 : take the complement (999 – 521) = – 478

Modular Addition

Counting upward on scale corresponds to addition

Example in 9’s complement: does not cross the

modulus

0

0 Representatio n 500 649 899 999 0 170 420 499 Number represented

- 499 **_- 350

100_** - 000 0 170 420 499

0

0

Addition with Wraparound

 Count to the right to add a negative number

 Wraparound scale used to extend the range for the

negative result

 Counting left would cross the modulus and give incorrect
answer because there are 2 values for 0 (+0 and -0)

9 Representatio n 500 999 0 200 499 500 899 999 Number represented

499

000 0 200 499 - 499 - 100

000

Wrong Answer!! + Representation 500 898 999 0 200 499 Number represented -499 -101 -000 0 200 499

  • 300

Overflow

Fixed word size has a fixed range size

Overflow: combination of numbers that adds

to result outside the range

End-around carry in modular arithmetic

avoids problem

Complementary arithmetic: numbers out of

range have the opposite sign

Test: If both inputs to an addition have the same

sign and the output sign is different, an overflow

occurred

1’s Binary Complement

 (^) Taking the complement : subtracting a value from a standard basis value

 Binary (base 2) system diminished radix complement
 Radix minus 1 = 2 – 1 1 as the basis

 (^) Inversion: change 1’s to 0’s and 0’s to 1s

 Numbers beginning with 0 are positive
 Numbers beginning with 1 are negative
 2 values for zero

 (^) Example with 8-bit binary numbers Numbers Negative Positive Representation method Complement Number itself Range of decimal numbers -127 10 -0 10 +0 10 12710 Calculation Inversion None Representation example 10000000 11111111 0000000 0111111