cosc 243 - university of · pdf filecosc 243 (computer architecture) ... – the roman...

46
COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 1 COSC 243 Data Representation 2

Upload: lamxuyen

Post on 24-Mar-2018

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 1

COSC 243

Data Representation 2

Page 2: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 2

Overview• Last Lecture

– Data representation 1• This Lecture

– Data representation 2• Positional notation• Positive integers• Negative integers

– Source: lecture & lecture notes & Chapter 9 of 10th edition• Next Lecture

– Data representation 3– Source: lecture & lecture notes

Page 3: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Mathematical Notation• Numeral / Digit - a single symbol representing a quantity

– In the case of the switches there are 2 (0 and 1)– In the case of “normal math” there are 10 (0,1,2,3,4,5,6,7,8,9)

• Number system - a way of assigning combinations of numerals to different quantities– The Roman system is different from the Hindu–Arabic system

• MCMXIII = 1913

• Positional number system – a way of assigning quantities to numerals based on their position– 1981 = 1 lot of a thousand, 9 of a hundred, 8 of ten and 1 of 1

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 3

Page 4: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Number Systems• In a positional system the base is the number of numerals• Base 10 (decimal) is used today by most cultures. It

originated in the 13th century BC in China.– Its easy because we have 10 fingers

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 4

Page 5: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Number Systems• The Mayas, Celts and Aztecs developed a base 20

(vigesimal ) number system

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 5

http://en.wikipedia.org/wiki/Vigesimal

Page 6: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Number Systems• The Sumerians and Babylonians developed a base 60

number system (sexagesimal)

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 6

http://en.wikipedia.org/wiki/Sexagesimal

Page 7: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Number Systems• Computers work in base 2 (binary)

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 7

Page 8: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Switches• Computer memory is made from (electronic) switches• Each switch can be either: off or on

– If the switch is off then electricity does not flow• We call this false or 0

– If the switch is on the electricity does flow• We call this true or 1

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 8

or

OFF ON

Page 9: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

A Single Switch• How many numbers can be represented with a single switch?

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 9

= 0

= 1

Page 10: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Two Switches• How many numbers can be represented with two switches?

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 10

= 00

= 01

= 10

= 11

Page 11: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Base 10 Numbers

• The base 10 system has 10 symbols (numerals / digits):0, 1, 2, 3, 4, 5, 6, 7, 8, 9

• Each digit in the number represents a power of 10– Working from the ‘.’

• Left increases +ve powers of 10• Right decreases –ve powers of 10

• 123.45= 1*102 + 2*101 + 3*100 + 4*10-1 + 5*10-2

= 100 + 20 + 3 + 4/10 + 5/100

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 11

Page 12: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Bases (The General Case)

• The general case is:

def.xyzb = d*b2 + e*b1 + f*b0 + x*b-1 + y*b-2 +z*b-3

• Where b is the base (specified as a subscript)

• If the base is less than or equal to 10 we (by convention) use the Hindu–Arabic digits, if it is greater than 10 we use alphabetical (Roman) letters. What if the base is larger than 36?

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 12

Page 13: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Bases

• What is the value of:

13460 = 1*602 + 3*601 + 4*600 (sexagesimal)13420 = 1*202 + 3*201 + 4*200 (vigesimal)

• What is the value of:002 = 012 =102 = 112 =

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 13

Page 14: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Binary

• What is the value of:002 = 012 =102 = 112 =

• When we see two switches togetherwe can interpret them as a number inbinary

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 14

= 00

= 01

= 10

= 11

Page 15: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Binary Number System

• We can use the computer’s memory (the switchbox) to represent numbers in binary (base 2).

• What is the value of:– on on off off on on?– 1100112

• 1*25 + 1*24 + 0*23 + 0*22 + 1*21 + 1*20

• 32 + 16 + 0 + 0 + 2 + 1• 51

– on on off “point” off on on– 110.0112

• 1*22 + 1*21 + 0*20 + 0*2-1 + 1*2-2 + 1*2-3

• 4 + 2 + 0 + 0 + 1/4 + 1/8• 6.375

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 15

Page 16: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Decimal to Binary Conversion

• Convert 38.687510 to binary (base 2)– We’ll do the 38 first then the .6875 second

• Repeatedly divide the whole number part by 2– The remainders are the answer (bottom to top)

• From the next slide: 3810 = 1001102

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 16

Page 17: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 17

Decimal to Binary Conversion (cont)

LSB = least significant bit MSB = most significant bit

Page 18: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Decimal to Binary Conversion (cont)

• Convert 38.687510 to binary (base 2)

• For the fractional part, multiply by 2. Split the result into an integer part and a fractional part. Continue multiplying the fractional part. Use the integer part from top to bottom.

• From the next slide: .687510 = .10112

• So, 38.6875 = 100110.10112

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 18

Page 19: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 19

Decimal to Binary Conversion (cont)

Page 20: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Repeating & Irrational Numbers

• When you turn a base 10 fraction into a decimal it may not terminate, the result may repeat “forever”: 1/3 = 0.33333...

• Given 1/10– What is the decimal equivalent?– What is the binary equivalent?

• In order to store the number we terminate significance at some arbitrary point (often specified by the programmer when they declare a variable (float or double in ‘C’)).

• π (pi) is an irrational number. It cannot be represented as a fraction. The approximation of 3.141592… never terminates and never repeats.

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 20

Page 21: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Binary to Decimal Conversion (cont)

• Working outward from the decimal point:100110.1011

= 32 + 0 + 0 + 4 + 2 + 0 + 1/2 + 0 + 1/8 + 1/16= 32 + 0 + 0 + 4 + 2 + 0 + (0.5 + 0 + 0.125 + 0.0625)= 38.6875

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 21

Page 22: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Binary to Decimal Conversion Table

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 22

Power (bit) 2Power Power (bit) 2Power

0 1 -1 0.51 2 -2 0.252 4 -3 0.1253 8 -4 0.06254 16 -5 0.031255 32 -6 0.0156256 64 -7 0.0078137 128 -8 0.0039068 2569 512

10 1,02411 2,04812 4,09613 8,19214 16,38415 32,76816 65,53617 131,07218 262,14419 524,28820 1,048,576

Page 23: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Octal Number System• Binary numbers get long quickly and so we group bits together and

use a larger base. 2 bits = base 4, 3 bits = base 8, 4 bits = base 16.

• The base 8 system (octal) uses the symbols: 0, 1, 2, 3, 4, 5, 6, 7. It takes 3 binary bits to make an octal digit. Group the binary digits in groups of 3 from the decimal point (the Least Significant Bit (LSB)).

• Octal gained popularity because some machines (such as the PDP-8) used 12-bit, 24-bit or 36-bit words and numbers could be easily displayed in 4, 8, and 12 (octal)digit displays. It was a cost and complexity saving. It isalso easy to learn.

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 23

Bin Oct000 0001 1010 2011 3100 4101 5110 6111 7258=010 1012 =2110

Page 24: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Hexadecimal Number System

• Today machines use 8-bit, 16-bit, 32-bit or 64-bit words. Using base 16 makes more sense. In hexadecimal (or hex) each digit is 4 bits. To make up the “missing” digits letters are used:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

• 4 bits (one digit) is a nybble. 2 nybbles is byte (8 bits). Words are whole powers of bytes. Hardware makes more sense today than it once did!

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 24

Page 25: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Hexadecimal Number System (cont)

• Take the binary number, e.g.:

100110110011111

• Group into chunks of 4 binary digits (right to left):

[0]100 1101 1001 1111

• Convert each group into its nybble:

4 D 9 F

• The resulting number is the hex:

1001101100111112 → 4D9F16

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 25

Bin Hex Bin Hex0000 0 1000 80001 1 1001 90010 2 1010 A0011 3 1011 B0100 4 1100 C0101 5 1101 D0110 6 1110 E0111 7 1111 F

Page 26: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Other Conversions

• Conversions:decimal→octal, decimal→hex, octal→decimal, and hex→decimal can be made using positional notation or similar techniques as binary→decimal and decimal→binary.

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 26

decimal binary

hex

octal

Page 27: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Introduction to Binary Arithmetic

• Plus– Exactly the same (algorithm) as base 10 addition

• Left to right:

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 27

136102710====16310

0011201012====10002

6 +7 = 3 (carry 1)3 + 2 + carry = 6 (carry 0)1 + carry = 1

1 + 1 = 0 (carry 1)1 + 0 + 1 = 0 (carry 1)0 + 1 + 1 = 0 (carry 1)0 + 0 + 1 = 1 (carry 0)

Page 28: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Introduction to Binary Arithmetic

• Minus– Exactly the same (algorithm) as base 10 subtraction

• Left to right:

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 28

136102710====10910

1001201012====01002

6 - 7 = 9 (borrow 10)3 - 2 - 1 (borrow) = 01 - 0 = 1

1 - 1 = 00 - 0 = 00 - 1 = 1 (borrow 2)1 - 0 - 1 (borrow) = 0

Page 29: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Introduction to Negative Integers

• So far we have concentrated on positive integers

• Remember that the memory is a set of switches, there is no decimal point and no negative sign, but we can devise a scheme to represent negative numbers (we’ll do real numbers in an upcoming lecture)

• 4 ways have been used:– Excess notation– Sign magnitude– One's complement– Two's complement

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 29

Page 30: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Excess Notation

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 30

• By convention we count from 0, but what if we count from a different number. If we count from -3 (excess 3) then:

Number Bits-3 000-2 001-1 0100 0111 1002 1013 1104 111

Page 31: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Excess Notation

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 31

• If we shift the numbers by about half the possible range then we get about the same number of positive and negative numbers

• Example:– The computer stores integer values in 8 bits, using excess 128

notation. How is -6010 stored?

stored number = -60 + 128

= 6810= 0100 01002

Page 32: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Excess Notation Example 2

• The binary number, 01011101, is in excess 128 notation. What is the number in decimal?

0101 1101 = 0 + 64 + 0 + 16 + 8 + 4 + 0 + 1

= 93 (excess 128)

decimal number = 93 - 128

= -35

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 32

Page 33: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Excess Notation• Most inconveniently, 0 (excess n) is not 0 in binary

• There must be a better way

• But, excess notation is used to store real numbers– upcoming lecture

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 33

Page 34: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Sign Magnitude

• Why not just use the most significant bit to represent the sign? This is so simple: 0 = positive, 1 = negative

• In 4 bits:

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 34

Bin Value Bin Value0000 0 1000 -00001 1 1001 -10010 2 1010 -20011 3 1011 -30100 4 1100 -40101 5 1101 -50110 6 1110 -60111 7 1111 -7

Page 35: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Sign Magnitude (cont)

• There are 2 values for 0! (+0 and -0)

• Addition and subtraction complicated– Compute the bit pattern for 2 - 3

• The range of integers is (2n-1-1) to -(2n-1-1)– Where n is the number of bits– Which is 1 fewer than Excess notation

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 35

Page 36: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

One’s Complement

• The negative is the complement of the positive– If positive, do nothing– If negative, complement (invert) each bit

84 = 0101 0100

-84 = 1010 1011

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 36

Page 37: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

One’s Complement

• Negation is easy– Invert the bit-pattern

• Addition and subtraction is easier– But there are still two values for zero

• Range of integers is (2n-1-1) to -(2n-1-1)– Where n is the number of bits• Which is 1 fewer than Excess notation

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 37

Page 38: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Two’s Complement• We want an encoding that:

– Has one encoding for 0 (000)– Binary addition and subtraction works– Addition “through zero” works– Has a sign bit– Subtraction is addition of negative numbers

• To convert a positive to two’s complement– Do nothing

• To convert a negative to two’s complement– Complement (invert the bits) then add 1

• The range of integers is (2n-1-1) to -(2n-1)COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 38

Decimal Binary-4 100-3 101-2 110-1 1110 0001 0012 0103 011

Page 39: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Example• Convert -84 to two’s complement (using 8 bits)

84 = 0101 0100

• Complement and add 1

11 ← carries

1010 1011 ← each bit complemented

+ 1

---------

1010 1100 ← -84 in two’s complement

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 39

Page 40: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Two’s Complement to Decimal

• If the high (sign) bit is 0– Convert the binary number to decimal

• If the high (sign) bit is 1– Complement (invert) each bit– Add 1 to the binary number– Convert the binary number to decimal– Put a minus sign in front of the decimal number

• This is the same as subtracting the positive number from 2n where n is the number of bits in the representation

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 40

Page 41: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Example• Convert the 8-bit number 1110 1010 in two’s complement to decimal

– Complement and add 1

1 <-- carry

0001 0101 <-- complement each bit

+ 1 <-- add 1

---------

0001 0110

0001 0110 = 16 + 4 + 2 = 22

• Answer = -22

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 41

Page 42: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Subtraction Example

• Subtract 5 from 18 in 8-bit, 2's complement18 – 5 = 18 + -5

18 = 0001 0010

-5 = 1111 1011

----------

10000 1101

• Dropping the high-order (9th) bit gives:[1] 0000 1101 = 13

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 42

Page 43: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Two’s Complement Example 2

• Subtract 5 from -18 in 8-bit, 2's complement-18 - 5 = -18 + -5

-18 = 1110 1110

-5 = 1111 1011

----------

11110 1001

• Ignoring the high-order (9th) bit gives:

[1] 1110 1001 = -23

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 43

Page 44: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 44

Two’s Complement Overflow

• The result is invalid if the addition of two positive numbers gives a negative number– This is easy to check (the high bit is 1!)

• The result is invalid if the addition of two negative numbers gives a positive number– This is easy to check (the high bit is 0!)

• These are (often) caught by the CPU as an overflow / underflow exception– This is then passed to your program as an exception

Page 45: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Homework I• Convert 0.110 into binary (use up-to 16 digits)

– Is it (a) representable, (b) repeating, (c) irrational

• Convert 0.2510 into octal (use up-to 16 digits)– Is it (a) representable, (b) repeating, (c) irrational

• Convert 0.310 into hexadecimal (use up-to 16 digits)– Is it (a) representable, (b) repeating, (c) irrational

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 45

Page 46: COSC 243 - University of · PDF fileCOSC 243 (Computer Architecture) ... – The Roman system is different from the Hindu–Arabic ... used 12-bit, 24-bit or 36-bit words and numbers

Homework II

COSC 243 (Computer Architecture) Lecture 2 - Data Representation 2 46

+= 10

The computer memory is a series of switches, we’ve brokenthem into 4 bytes of 8 switches. Add the 4 x 8-bit binarynumbers to get a binary number. Convert that into base 10. Dothe same assuming two’s complement encoding.