Number systems Digital The basics: Binary numbers Binary → hex

Loading...

Number systems

Digital

! Last lecture " Course overview " The Digital Age

! Digital = discrete " Binary codes (example: BCD) " Decimal digits 0-9 " DNA nucleotides

! Today’s lecture " Binary numbers " Base conversion " Number systems

! Binary codes " Represent symbols using binary digits (bits)

# Twos-complement "

! Digital computers: " I/O is digital

A/D and D/A conversion

# ASCII, decimal, etc. "

Internal representation is binary

Decimal Symbols 0 1 2 3 4 5 6 7 8 9

BCD Code 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

# Process information in bits

CSE370, Lecture 2

1

CSE370, Lecture 2

The basics: Binary numbers

Binary → hex/decimal/octal conversion

! Bases we will use " Binary: Base 2 " Octal: Base 8 " Hexadecimal: Base 16

! Conversion from binary to octal/hex " Binary: 10011110001 " Octal: 10 | 011 | 110 | 001=23618 " Hex: 100 | 1111 | 0001=4F116

! Positional number system 2 1 0 " 1012= 1×2 + 0×2 + 1×2 1 0 " 638 = 6×8 + 3×8 1 0 " A116= 10×16 + 1×16

! Conversion from binary to decimal 2 1 0 " 1012= 1×2 + 0×2 + 1×2 = 510 1 0 –1 " 63.48 = 6×8 + 3×8 + 4×8 = 51.510 1 0 " A116= 10×16 + 1×16 = 16110

2

! Addition and subtraction 1011 + 1010

1011 – 0110 0101

10101 CSE370, Lecture 2

3

Decimal→ binary/octal/hex conversion Binary 56÷2= 28÷2= 14÷2= 7÷2= 3÷2= 1÷2=

28 14 7 3 1 0

0 0 0 1 1 1

! How do we write negative binary numbers? ! Historically: 3 approaches " Sign-and-magnitude " Ones-complement " Twos-complement

Quotient Remainder 56÷8= 7÷8=

7 0

0 7

5610=1110002 5610=708

! For all 3, the most-significant bit (msb) is the sign digit " 0 ≡ positive " 1 ≡ negative

! Why does this work? " N=5610=1110002 " Q=N/2=56/2=111000/2=11100 remainder 0

! Learn twos-complement " Simplifies arithmetic " Used almost universally

! Each successive divide liberates an LSB CSE370, Lecture 2

4

Number systems

Octal

Quotient Remainder

CSE370, Lecture 2

5

CSE370, Lecture 2

6

Sign-and-magnitude

Ones-complement

! The most-significant bit (msb) is the sign digit " 0 ≡ positive " 1 ≡ negative

! Negative number: Bitwise complement positive number " 0011 ≡ 310 " 1100 ≡ –310

! The remaining bits are the number’s magnitude

! Solves the arithmetic problem

! Problem 1: Two representations for zero " 0 = 0000 and also –0 = 1000

4 +3 =7

! Problem 2: Arithmetic is cumbersome Add 4 +3 =7

0100 + 0011 = 0111

Subtract 4 – 3 =1

0100 + 1011 ≠ 1111

Add

Invert, add, add carry

Invert and add

0100 + 0011 = 0111

4 –3 =1 add carry:

–4 +3 –1

Compare and subtract

0100 – 0011 = 0001

–4 +3 –1

1100 + 0011 ≠ 1111

1011 + 0011 1110

! Remaining problem: Two representations for zero " 0 = 0000 and also –0 = 1111

1100 – 0011 = 1001

CSE370, Lecture 2

0100 + 1100 1 0000 +1 = 0001

7

CSE370, Lecture 2

8

Twos-complement

Twos-complement (con’t)

! Negative number: Bitwise complement plus one " 0011 ≡ 310 " 1101 ≡ –310

! Complementing a complement $ the original number

–1

! Number wheel ! Only one zero! ! msb is the sign digit " 0 ≡ positive " 1 ≡ negative

–2

–4

1111

0001

1101

# Easy to implement in hardware

+1

0000

1110

–3

! Arithmetic is easy " Subtraction = negation and addition

0 +2

0010

1100

0011

– 5 1011 1010 –6 1001 1000

–7

–8

Add

+3

4 +3 =7

0100 + 4 0101 +5

0110 0111

Invert and add

0100 + 0011 = 0111

4 –3 =1 drop carry

0100 + 1101 1 0001 = 0001

Invert and add –4 +3 –1

1100 + 0011 1111

+6

+7

CSE370, Lecture 2

9

CSE370, Lecture 2

10

Miscellaneous

Twos-complement overflow

! Twos-complement of non-integers " 1.687510 = 01.10112 " –1.687510 = 10.01012

! Summing two positive numbers gives a negative result ! Summing two negative numbers gives a positive result

! Sign extension " Write +6 and –6 as twos complement # 0110 and 1010 "

Sign extend to 8-bit bytes # 00000110 and 11111010

! Can’t infer a representation from a number " 11001 is 25 (unsigned) " 11001 is –9 (sign magnitude) " 11001 is –6 (ones complement) " 11001 is –7 (twos complement) CSE370, Lecture 2

11

–1 0 –2 1111 0000 + 1 1110 0001 + 2 –3 1101 0010 – 4 1100 0011 + 3

–1 0 –2 1111 0000 + 1 1110 0001 + 2 –3 1101 0010 – 4 1100 0011 + 3

0100 + 4 – 5 1011 1010 0101 –6 1001 0110 + 5 1000 0111 + 6 –7 –8 +7

0100 + 4 – 5 1011 1010 0101 –6 1001 0110 + 5 1000 0111 + 6 –7 –8 +7

6 + 4 ⇒ –6

–7 – 3 ⇒ +6

CSE370, Lecture 2

12

Twos-complement overflow (cont’d) ! Correct results

! Incorrect results

Gray and BCD codes

1111 –1 + 1010 –6

0011 +3 + 0010 +2

1 1001 –7

0101 +5

0110 +6 + 0100 +4

1001 + 1010

–7 –6

1010 –6

1 0011

+3

! Overflow condition " Carry from 2sb-msb and carry from msb-Cout are different

2sb-msb 0 0 1 1

msb-Cout Overflow 0 0 1 1 0 1 1 0

CSE370, Lecture 2

13

Decimal Symbols 0 1 2 3 4 5 6 7 8 9

Gray Code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101

Sampling

! Digital systems need to " Measure analog quantities

! Quantization " Conversion from analog to discrete values

"

Control analog systems

BCD Code 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

CSE370, Lecture 2

The physical world is analog

# Speech waveforms, etc

Decimal Symbols 0 1 2 3 4 5 6 7 8 9

14

! Quantizing a signal " We sample it

# Drive motors, etc

! How do we connect the analog and digital domains? " Analog-to-digital converter (ADC or A/D) # Example: CD recording "

Digital-to-analog converter (DAC or D/A) # Example: CD playback

Datel Data Acquisition and Conversion Handbook

CSE370, Lecture 2

15

Conversion ! Encoding " Assigning a digital word to each discrete value ! Encoding a quantized signal " Encode the samples " Typically Gray or binary codes

Datel Data Acquisition and Conversion Handbook

CSE370, Lecture 2

17

CSE370, Lecture 2

16

Loading...

Number systems Digital The basics: Binary numbers Binary → hex

Number systems Digital ! Last lecture " Course overview " The Digital Age ! Digital = discrete " Binary codes (example: BCD) " Decimal digits 0-9 "...

85KB Sizes 6 Downloads 35 Views

Recommend Documents

Digital Systems and Binary Numbers
Digital Systems. ▫ Binary Numbers. ▫ Number-Base Conversions. ▫ Octal and Hexadecimal Numbers. ▫ Complements. â–

Digital Systems and Binary Numbers
[PDF]Digital Systems and Binary Numbershttp://eclass.duth.gr/.../Pages%20from%20DIGITAL%20SYSTEM%20DESIGN%20...CachedTh

Chapter 1 Digital Systems and Binary Numbers | Binary Coded
Digital Logic Design I. Chapter 1. Digital Systems and Binary Numbers. Title: Digital Design Code: Lecture: 3. Pre-Requi

1 Digital Systems and Binary Numbers
Digital Logic Design. Yarmouk University. Computer Engineering Department. ID= Chapter 1 - Binary Systems. 1 Digital Sys

Binary Numbers
Binary numbers. A rudimentary knowledge of how binary numbers work is required in order to understand the mechanism of d

Digital Electronics: Binary Basics - dummies
By Doug Lowe. Digital electronic circuits rely on the binary number system. Thus, before you can understand the details

Numeral Systems - Binary, Octal, Decimal, Hex - RapidTables.com
Binary number system, decimal number system, hexadecimal number system, base 2, base 8, base 10, base 16.

Binary Numbers
Binary Numbers. • COUNTING SYSTEMS UNLIMITED . . . Since you have been using the. 10 different digits 0, 1, 2, 3, 4, 5

Binary Number Systems - The PLC Tutor
The binary number system is used by all computers, PLC/PAC's and digital device. The binary number system is a base-2 nu

the binary number system
1.1 Introduction. Given that digital logic and memory devices are based on two electrical states (on and off), it is nat