Lecture 1 Binary Representation Topics Terminology Base 10, Hex, binary Fractions Base-r to decimal...

Post on 16-Jan-2016

218 views 0 download

transcript

Lecture 1Binary Representation

Lecture 1Binary Representation

TopicsTopics Terminology Base 10, Hex, binary Fractions Base-r to decimal Unsigned Integers Signed magnitude Two’s complement

August 24, 2015

CSCE 211H Digital Design

– 2 – CSCE 211H Fall 2015

OverviewOverview

Readings Chapter 1Readings Chapter 1 Overview of Course Analog vs Digital Conversion Base-r to decimal Conversion decimal to Base-r Conversion of Fractions base-r decimal Unsigned Arithmetic Signed Magnitude Two’s Complement Excess-1023

Click to edit Master subtitle styleClick to edit Master subtitle styleCopyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 1

Introduction

– 4 – CSCE 211H Fall 2015

Course OutcomesCourse Outcomes1.1. Represent numbers and perform arithmetic in bases 2, 8, and 16Represent numbers and perform arithmetic in bases 2, 8, and 16

2.2. Encode symbols and numbers in binary codesEncode symbols and numbers in binary codes

3.3. Add and subtract using 2’s complement codeAdd and subtract using 2’s complement code

4.4. Evaluate and simplify logical functions using Boolean algebraEvaluate and simplify logical functions using Boolean algebra

5.5. Represent logical functions in Canonical form and with GatesRepresent logical functions in Canonical form and with Gates

6.6. Analyze and design combinatorialAnalyze and design combinatorial

7.7. Simplify combinatorial circuits using Karnaugh Simplify combinatorial circuits using Karnaugh

8.8. Implement functions with NAND-NAND and NOR-NOR logicImplement functions with NAND-NAND and NOR-NOR logic

9.9. Analyze and design modular combinatorial logic circuits containing Analyze and design modular combinatorial logic circuits containing decoders, multiplexers, demultiplexers, 7-segments display decoders and decoders, multiplexers, demultiplexers, 7-segments display decoders and addersadders

10.10. Use the concepts of state and state transition for analysis and design of Use the concepts of state and state transition for analysis and design of sequential circuitssequential circuits

11.11. Use the functionality of flip-flops for analysis and design of sequential Use the functionality of flip-flops for analysis and design of sequential circuitscircuits

12.12. Software-hardware co-design (Arduino)Software-hardware co-design (Arduino)

– 5 – CSCE 211H Fall 2015Comp. Arch. Quantitative Approach - H&P Chapter 1: Figure1.1

Performance Growth since 1978Performance Growth since 1978

– 6 – CSCE 211H Fall 2015

Analog vs digital: Why BinaryAnalog vs digital: Why Binary

– 7 – CSCE 211H Fall 2015

Other basesOther bases

Binary = Base 2Binary = Base 2

Hexadecimal = Base 16Hexadecimal = Base 16

Octal = Base 8Octal = Base 8

NotationsNotations Subscript In C

Conversions between basesConversions between bases

– 8 – CSCE 211H Fall 2015

Note that the number one less than 2n consists of n 1’s (for example, 24 – 1 = 1111 = 15 and 25 – 1 = 11111 = 31).

– 9 – CSCE 211H Fall 2015

Base-r to Decimal ConversionsBase-r to Decimal Conversions

Converting base-r to decimal by definitionConverting base-r to decimal by definition

ddnndd

n-1n-1dd

n-2n-2…d…d

2 2dd

1 1dd

0 0(base r)(base r) = d = d

nnrrnn + d + d

n-1n-1rrn-1n-1… d… d

22rr22 +d +d

1 1rr1 + 1 + dd

0 0rr00

ExampleExample

4F0C4F0C1616 = = 4*164*1633 + F*16 + F*1622 + 0*16 + 0*1611 + C*16 + C*1600

== 4*4096 + 15*256 + 0 + 12*1 4*4096 + 15*256 + 0 + 12*1

= = 16384 + 3840 + 1216384 + 3840 + 12

== 2023620236

– 10 – CSCE 211H Fall 2015

Decimal to Base-r ConversionDecimal to Base-r Conversion

Repeated division algorithmRepeated division algorithm

Justification:Justification:

ddnndd

n-1n-1dd

n-2n-2…d…d

2 2dd

1 1dd

0 0 = d = d

nnrrnn + d + d

n-1n-1rrn-1n-1… d… d

22rr22 +d +d

1 1rr1 + 1 + dd

0 0rr00

Dividing each side by r yieldsDividing each side by r yields

(d(dnndd

n-1n-1dd

n-2n-2…d…d

2 2dd

1 1dd

0 0) / r = d) / r = d

nnrrn-1n-1 + d + d

n-1n-1rrn-2n-2… d… d

22rr11+d+d

1 1rr0 + 0 + dd

0 0rr-1-1

So dSo d 0 0 is the remainder of the first division is the remainder of the first division

((q((q11) / r = d) / r = d

nnrrn-2n-2 + d + d

n-1n-1rrn-3n-3… d… d

33rr11+d+d

2 2rr0 + 0 + dd

1 1rr-1-1

So dSo d 1 1 is the remainder of the next division is the remainder of the next division

and dand d 2 2 is the remainder of the next division is the remainder of the next division

……

– 11 – CSCE 211H Fall 2015

Decimal to Base-r Conversion ExampleDecimal to Base-r Conversion Example

Repeated division algorithm ExampleRepeated division algorithm Example

Convert 4343 to hexConvert 4343 to hex

4343/16 = 271 remainder = 74343/16 = 271 remainder = 7

271/16 = 16 remainder = 15271/16 = 16 remainder = 15

16/16 = 1 remainder = 0 16/16 = 1 remainder = 0

1/16 = 0 remainder = 11/16 = 0 remainder = 1

So 4343So 43431010

= 10F7 = 10F71616

To check the answer convert back to decimalTo check the answer convert back to decimal

10F7 = 1*1610F7 = 1*1633 + 15*16 + 7*1 = 4096 + 240 + 7 = 4343 + 15*16 + 7*1 = 4096 + 240 + 7 = 4343

– 12 – CSCE 211H Fall 2015

Hex to BinaryHex to Binary

One hex digit = four binary digitsOne hex digit = four binary digits

ExampleExample

3FAC = 0011 1111 1010 1100 3FAC = 0011 1111 1010 1100 (spaces just for readability)(spaces just for readability)

Binary to hex Binary to hex four binary digits one hex digit (group from right!!!)

ExampleExample

101101001111010 = 0010 1101 0011 1010101101001111010 = 0010 1101 0011 1010

= 2 D 3= 2 D 3 AA

– 13 – CSCE 211H Fall 2015

Hex to Decimal FractionsHex to Decimal Fractions

.d.d-1-1dd

-2-2dd

-3-3…d…d

–(n-2) –(n-2)dd

–(n-1) –(n-1)dd

-n -n= d= d

-1-1rr-1-1 + d + d

-2-2rr-2-2…d…d

-(n-1)-(n-1)rr-(n-1)-(n-1) +d +d

1 1rr-n-n

ExampleExample

.1EF.1EF1616

= 1*16= 1*16-1-1 + E*16 + E*16-2-2 + F*16 + F*16-3-3

= 1*.0625 + 14*.003906025 + 15*2.4414e-= 1*.0625 + 14*.003906025 + 15*2.4414e-44

= .117201… (probably close but not = .117201… (probably close but not right)right)

– 14 – CSCE 211H Fall 2015

Example: Hex Fractions to decimalExample: Hex Fractions to decimal

Convert .3FA to decimalConvert .3FA to decimal

.3FA.3FA1616 = 3*16 = 3*16-1-1 + F*16 + F*16-2-2 + A*16 + A*16-3-3

= 3*.0625 + 15*.00390625 +10* (1/4096)= 3*.0625 + 15*.00390625 +10* (1/4096)

= .191162109= .191162109

– 15 – CSCE 211H Fall 2015

Decimal Fractions to hexDecimal Fractions to hex

.d.d-1-1dd

-2-2dd

-3-3…d…d

–(n-2) –(n-2)dd

–(n-1) –(n-1)dd

-n -n= d= d

-1-1rr-1-1 + d + d

-2-2rr-2-2…d…d

-(n-1)-(n-1)rr-(n-1)-(n-1) +d +d

1 1rr-n-n

Multiplication by r yields Multiplication by r yields

r *(.dr *(.d-1-1rr-1-1 + d + d

-2-2rr-2-2…d…d

-(n-1)-(n-1)rr-(n-1)-(n-1) +d +d

1 1rr-n-n ) )

= d= d-1-1rr00 + d + d

-2-2rr-1-1…d…d

-(n-1)-(n-1)rr-(n-2)-(n-2) +d +d

1 1rr-(n-1)-(n-1)

Whole number part = dWhole number part = d-1-1rr00

Multiplying again by r yields dMultiplying again by r yields d-2-2rr0 0 as the whole number as the whole number

partpart

… … till fraction = 0till fraction = 0

– 16 – CSCE 211H Fall 2015

Example Decimal Fraction to hexExample Decimal Fraction to hex

By repeated multiplicationBy repeated multiplication

– 17 – CSCE 211H Fall 2015

Unsigned integersUnsigned integers

What is the binary representation of the biggest integer What is the binary representation of the biggest integer representable using n-bits(n binary digits)?representable using n-bits(n binary digits)?

What is its value in decimal?What is its value in decimal?

Special casesSpecial cases

8 bits8 bits

16 bits16 bits

32 bits32 bits

– 18 – CSCE 211H Fall 2015

Arithmetic with Binary NumbersArithmetic with Binary Numbers

10010110 10010110 1001011010010110 11011101

+00110111+00110111 - 00110111- 00110111 x 101x 101

Problems with 8 bit operationsProblems with 8 bit operations

1001011010010110

++ 1001011010010110

– 19 – CSCE 211H Fall 2015

– 20 – CSCE 211H Fall 2015

Signed integersSigned integers

How do we represent?How do we represent?

Signed-magnitudeSigned-magnitude

Excess representationsExcess representations

w bits w bits 0 <= unsigned_value < 2 0 <= unsigned_value < 2ww

In excess-B we subtract the bias (B) to get the value.In excess-B we subtract the bias (B) to get the value.

exampleexample

– 21 – CSCE 211H Fall 2015

Complement Representations of Signed integersComplement Representations of Signed integers

One’s complementOne’s complement

Two’s complementTwo’s complement

– 22 – CSCE 211H Fall 2015

Two’s Complement OperationTwo’s Complement Operation

One’s complement + 1 orOne’s complement + 1 or

Find rightmost 1, complement all bits to the left of it.Find rightmost 1, complement all bits to the left of it.

ExamplesExamples

0100111001001110 0000000100000001 0000000000000000 0000001000000010

– 23 – CSCE 211H Fall 2015

Two’s Complement RepresentationTwo’s Complement Representation

Consider a two’s complement binary numberConsider a two’s complement binary number

ddnndd

n-1n-1dd

n-2n-2…d…d

2 2dd

1 1dd

0 0

If dIf dn n , the sign bit = 0 the number is positive and its , the sign bit = 0 the number is positive and its

magnitude is given by the other bits.magnitude is given by the other bits.

If dIf dn n , the sign bit = 1 the number is negative and take its , the sign bit = 1 the number is negative and take its

two’s complement to get the magnitude.two’s complement to get the magnitude.

Weighted Sum InterpretationWeighted Sum Interpretation

0 10 1

1 21 2

……

n-1 2 n-1 2 n-2n-2

n -2 n -2 n-1n-1

– 24 – CSCE 211H Fall 2015

Two’s Complement RepresentationTwo’s Complement Representation

Consider a two’s complement binary numberConsider a two’s complement binary number

ddnndd

n-1n-1dd

n-2n-2…d…d

2 2dd

1 1dd

0 0

If dIf dn n , the sign bit = 0 the number is positive and its , the sign bit = 0 the number is positive and its

magnitude is given by the other bits.magnitude is given by the other bits.

If dIf dn n , the sign bit = 1 the number is negative and take its , the sign bit = 1 the number is negative and take its

two’s complement to get the magnitude.two’s complement to get the magnitude.

Weighted SumWeighted Sum

0 10 1 Example 10010011 = Example 10010011 = 1 21 2

……

n-1 2 n-1 2 n-2n-2

n -2 n -2 n-1n-1

– 25 – CSCE 211H Fall 2015

Two’s Complement RepresentationTwo’s Complement Representation

What is the 2’s complement representation in 16 bits of What is the 2’s complement representation in 16 bits of –5?–5?

+7?+7?

-1?-1?

00

-2-2

– 26 – CSCE 211H Fall 2015

– 27 – CSCE 211H Fall 2015

Arithmetic with Signed IntegersArithmetic with Signed Integers

Signed Magnitude AdditionSigned Magnitude Addition

if the signs are the same add the magnitude if the signs are the same add the magnitude

if the signs are different subtract the smaller from if the signs are different subtract the smaller from the larger and use the sign of the largerthe larger and use the sign of the larger

Subtraction?Subtraction?

Two’s complementTwo’s complement

Just add signs take care of themselvesJust add signs take care of themselves

– 28 – CSCE 211H Fall 2015

Overflow in Two’s ComplementOverflow in Two’s Complement

– 29 – CSCE 211H Fall 2015

– 30 – CSCE 211H Fall 2015

Binary Code DecimalBinary Code Decimal Floating point – IEEE 754Floating point – IEEE 754

– 31 – CSCE 211H Fall 2015

Representations of CharactersRepresentations of Characters

– 32 – CSCE 211H Fall 2015

– 33 – CSCE 211H Fall 2015

ASCII Message on the WallASCII Message on the WallPrinceton CS Building West Wall BricksPrinceton CS Building West Wall Bricks

This brick pattern is located on the west wall of the This brick pattern is located on the west wall of the Computer Science building, and dates back to 1989, Computer Science building, and dates back to 1989, when the building was constructed. The pattern is when the building was constructed. The pattern is read top to bottom and consists of five 7-bit ASCII read top to bottom and consists of five 7-bit ASCII values. The vertical lines to the left and right are values. The vertical lines to the left and right are "framing" bits. (Table 1.8 page 18 previous slide)"framing" bits. (Table 1.8 page 18 previous slide)

x 1 0 1 0 0 0 0 x x 1 0 1 0 0 0 0 x

x 0 1 1 1 1 0 1 x x 0 1 1 1 1 0 1 x

x 1 0 0 1 1 1 0 x x 1 0 0 1 1 1 0 x

x 1 0 1 0 0 0 0 x x 1 0 1 0 0 0 0 x

x 0 1 1 1 1 1 1 x x 0 1 1 1 1 1 1 x This pattern asks _________?This pattern asks _________?http://www.cs.princeton.edu/general/bricks

– 34 – CSCE 211H Fall 2015

– 35 – CSCE 211H Fall 2015

Basic GatesBasic Gates

ANDAND

OROR

NOTNOT

– 36 – CSCE 211H Fall 2015

Basic GatesBasic Gates

NANDNAND

NORNOR

XORXOR

– 37 – CSCE 211H Fall 2015

Half Adder Circuit; Full AdderHalf Adder Circuit; Full Adder

– 38 – CSCE 211H Fall 2015

Homework Due at the start of class WednesdayHomework Due at the start of class WednesdayPage 25Page 25

1.1.1.*a, b,f1.*a, b,f

2.2.2h2h

3.3.3b3b

4.4.4b4b

5.5.5a, 5c5a, 5c

6.6.7a,b7a,b

7.7.Convert 137.125 to hex and then to binaryConvert 137.125 to hex and then to binary

8.8.Convert 137.1 to hex, rounding to 6 hex digits after the Convert 137.1 to hex, rounding to 6 hex digits after the “decimal” point.“decimal” point.