Docsity

computer hardware and system software 4, Slides of Computer Fundamentals

Partial preview of the text

Download computer hardware and system software 4 and more Slides Computer Fundamentals in PDF only on Docsity!

MIS 2103

Computer Hardware and

System Software

Fall 202 3

Lecture # 4

Internal Computer Data Format

§ All data stored as binary numbers

§ Interpreted based on

§ Operations computer can perform

§ Data types supported by programming

language used to create application

Number Representation

§ Numbers can be represented as a

combination of

§ Value or magnitude (or modulus)

§ Sign (plus or minus)

32 - bit Data Word

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

Conventional Binary vs. BCD

§ Binary representation generally

preferred

§ Greater range of value for given number of

bits

§ Calculations easier

§ BCD often used in business

applications to maintain decimal

rounding and decimal precision

4 - 10

Signed-Integer Representation

§ No obvious direct way to represent the

sign in binary notation

§ Options:

§ Sign-and-magnitude representation

§ 1’s complement

§ 2’s complement (most common)

SIGN Magnitude

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
    • 2
  • 4

Complementary Representation

§ Sign of the number does not have to be

handled separately

§ Consistent for all different signed

combinations of input numbers

§ Complement of a binary number is obtained

by inverting the value of each bit in the

number

Choice of Representation

§ Must be consistent with rules of normal

arithmetic

§ - (-value) = value

§ If we complement the value twice, it

should return to its original value

§ Complement = basis – value

§ Complement twice

p Basis – (basis – value) = value

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

Addition

§ Add 2 positive 8-bit

numbers

§ Add 2 8-bit numbers

with different signs

§ Take the 1’s

complement of 58

(i.e., invert)

Invert to get
magnitude