Lecture1 - Number Systems

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Number Systems

Computer Arithmetic

CS 21 - Computer Organization and Assembly Language Programming


Lecture 1 Number Systems and Computer Arithmetic

University of the Philippines - Diliman College of Engineering Department of Computer Science

Number Systems

Computer Arithmetic

Outline

Number Systems

Computer Arithmetic

Number Systems

Computer Arithmetic

Outline

Number Systems

Computer Arithmetic

Number Systems

Computer Arithmetic

Number systems
1 2

numbers could be represented in any base in a base system, digits used range from 0 to (base - 1). For example, in base 3, digits 0, 1 and 2 are used. prex/subscript/sux used in indicating what base representation was used

Number Systems

Computer Arithmetic

Number systems
1 2

numbers could be represented in any base in a base system, digits used range from 0 to (base - 1). For example, in base 3, digits 0, 1 and 2 are used. prex/subscript/sux used in indicating what base representation was used which of the following is an invalid number?

Number Systems

Computer Arithmetic

Binary Number System

1 2

base 2 natural for computers - on and o signals base 10 natural for human - why?

Number Systems

Computer Arithmetic

Decimal to Binary
Conversion from Decimal to Binary: 1 Divide the decimal number by 2, store the remainder 2 Continuously divide until quotient becomes less than 1 3 Read the remainders in reverse acquisition order

Number Systems

Computer Arithmetic

Question

What is the highest number we could represent using n-bits?

Number Systems

Computer Arithmetic

Binary to Decimal
Conversion from Binary to Decimal:
1

Starting from the right, multiply the binary digit by powers of 2. Begin at 2 raised to 0(which is 1). Add sums

Number Systems

Computer Arithmetic

Hexadecimal Number System


Hexadecimal Digits - Decimal equivalent 1=1 2=2 3=3 4=4 5=5 6=6 7=7 8=8 9=9 A = 10 B = 11 C = 12 D = 13 E = 14 F = 15

Number Systems

Computer Arithmetic

Decimal to Hexadecimal Conversion

How to convert from Decimal to Hexadecimal? Vice-versa?

Number Systems

Computer Arithmetic

Decimal to Hexadecimal Conversion

How to convert from Decimal to Hexadecimal? Vice-versa? same procedure as Decimal to Binary/Binary to Decimal - just replace the divisor by 16, and the powers of 2 by powers of 16!

Number Systems

Computer Arithmetic

Hexadecimal and Binary


Remember: Bit = smallest unit Nibble = 4 bits Byte = 8 bits or 2 nibbles Word = depends on number of bits in processor

Number Systems

Computer Arithmetic

Hexadecimal and Binary


Remember: Bit = smallest unit Nibble = 4 bits Byte = 8 bits or 2 nibbles Word = depends on number of bits in processor Binary Shorthand 1 hexadecimal digit could represent the value of 4 bits when converting from binary to hexadecimal, no need to pass through decimal format

Number Systems

Computer Arithmetic

Hexadecimal and Binary


Remember: Bit = smallest unit Nibble = 4 bits Byte = 8 bits or 2 nibbles Word = depends on number of bits in processor Binary Shorthand 1 hexadecimal digit could represent the value of 4 bits when converting from binary to hexadecimal, no need to pass through decimal format

Note that this could be done for octal as well

Number Systems

Computer Arithmetic

Outline

Number Systems

Computer Arithmetic

Number Systems

Computer Arithmetic

Arithmetic Operation: Addition


An Example: What is 1001 + 0101? Is this correct?

Number Systems

Computer Arithmetic

Arithmetic Operation: Addition


Solve: 1001 + 0101. Remember, possible sums of 2 addend bits are 0, 1 and 2. A single sum bit is not enough to represent all those!

Number Systems

Computer Arithmetic

Arithmetic Operation: Addition


Solve: 1001 + 0101. Remember, possible sums of 2 addend bits are 0, 1 and 2. A single sum bit is not enough to represent all those!
Solution: carryout!

Number Systems

Computer Arithmetic

Arithmetic Operation: Addition


Solve: 1001 + 0101. Remember, possible sums of 2 addend bits are 0, 1 and 2. A single sum bit is not enough to represent all those!
Solution: carryout!

So in each column, how many bits are we actually adding?

Number Systems

Computer Arithmetic

Arithmetic Operation: Addition


Solve: 1001 + 0101. Remember, possible sums of 2 addend bits are 0, 1 and 2. A single sum bit is not enough to represent all those!
Solution: carryout!

So in each column, how many bits are we actually adding?

Number Systems

Computer Arithmetic

Overow
What is overow? Overow indicates an insuciency of the number of our bits to represent the sum

Number Systems

Computer Arithmetic

Overow
What is overow? Overow indicates an insuciency of the number of our bits to represent the sum How is this detected?

Number Systems

Computer Arithmetic

Overow
What is overow? Overow indicates an insuciency of the number of our bits to represent the sum How is this detected?
If the CARRYOUT value of the LEFTMOST digits is 1, overow occured.

Number Systems

Computer Arithmetic

Arithmetic Operation: Multiplication

How could we do multiplication? Could we pull o multiplication using just ADDITION?

Number Systems

Computer Arithmetic

Arithmetic Operation: Multiplication

How could we do multiplication? Could we pull o multiplication using just ADDITION? Yes! Multiplication is just a repeated addition

Number Systems

Computer Arithmetic

Arithmetic Operation: Multiplication

How could we do multiplication? Could we pull o multiplication using just ADDITION? Yes! Multiplication is just a repeated addition Take note: Another possible hardware solution - ROM!

Number Systems

Computer Arithmetic

Arithmetic Operation: Subtraction

How could we do subtraction? What is subtraction in essence anyway?

Number Systems

Computer Arithmetic

Arithmetic Operation: Subtraction

How could we do subtraction? What is subtraction in essence anyway? Its just an addition between oppositely signed numbers 1-1=0 1 + (-) 1 = 0

Number Systems

Computer Arithmetic

Signed Binary Numbers

How do we represent negative binary numbers?

Number Systems

Computer Arithmetic

Signed Binary Numbers

How do we represent negative binary numbers? We use 2C or Twos Complement Notation.

Number Systems

Computer Arithmetic

Twos Complement Notation

We get the negative of a binary number by doing the following:

Number Systems

Computer Arithmetic

Twos Complement Notation

We get the negative of a binary number by doing the following:


1

Get the complement of each and every digit in the number. This is called its Ones Complement Representation

Number Systems

Computer Arithmetic

Twos Complement Notation

We get the negative of a binary number by doing the following:


1

Get the complement of each and every digit in the number. This is called its Ones Complement Representation

Add 1 to the Ones Complement

Number Systems

Computer Arithmetic

Twos Complement Notation

Why dont we just use the 1C Notation?

Number Systems

Computer Arithmetic

Twos Complement Notation

Why dont we just use the 1C Notation? There are 2 representations for 0: 0000 and 1111 - confusing!

Number Systems

Computer Arithmetic

Twos Complement Notation

Characteristics of Twos Complement Notation Leftmost digit tells us whether the number is positive or negative - 0 for positive, 1 for negative

Number Systems

Computer Arithmetic

Twos Complement Notation

Characteristics of Twos Complement Notation What is the implication of this for the representable range?

Number Systems

Computer Arithmetic

Twos Complement Notation

Characteristics of Twos Complement Notation Binary numbers in 2C notation would usually have the subscript 2C to dierentiate from those in ordinary notation
Do we convert to decimal the same way as before?

Number Systems

Computer Arithmetic

Overow in 2C Addition

How do we detect overow in 2C addition? Leftmost CARRYOUT value no longer indicative. Instead, we check the signs of addends and sum.
If signs of operands are dierent, overow could NOT occur! (subtraction) If signs of operands are the same, sum MUST also have the same sign. If not, then overow occured.

Number Systems

Computer Arithmetic

Usage

Where do we use unsigned numbers? 2C? 2C notation is used where signed numbers are needed - data. Unsigned notation used in character-encoding schemes and addresses.

Number Systems

Computer Arithmetic

Usage

Where do we use unsigned numbers? 2C? 2C notation is used where signed numbers are needed - data. Unsigned notation used in character-encoding schemes and addresses.
ASCII Unicode

Number Systems

Computer Arithmetic

ASCII

Number Systems

Computer Arithmetic

Unicode

Number Systems

Computer Arithmetic

So...

Any questions?

You might also like