Anda di halaman 1dari 48

CE211 Digital Systems

Binary Systems

Digital Systems Discrete Data


Examples:
26 letters of the alphabet (A, B etc) 10 decimal digits (0, 1, 2 etc)
Analog Discrete

Combine together
Words are made of letters (University etc) Numbers are made of digits (4241 etc)

Binary System
Only 0 and 1 digits Can be easily implemented in electronic circuits
1 / 47

Decimal Number System Base (also called radix) = 10


10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }

Digit Position
Integer & fraction

-1

-2

5 1 2
100 10 1

7 4
0.1 0.01

Digit Weight
Weight = (Base) Position

Magnitude
Sum of Digit x Weight

500

10

0.7 0.04

d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

Formal Notation

(512.74)10
2 / 47

Octal Number System Base = 8


8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }

Weights
Weight = (Base) Position

64

1/8 1/64

5 1 2
2
2

7 4
-1
0 -1

Magnitude
Sum of Digit x Weight

1
1

-2
-2

5 *8 +1 *8 +2 *8 +7 *8 +4 *8

=(330.9375)10 (512.74)8

Formal Notation

3 / 47

Binary Number System Base = 2


2 digits { 0, 1 }, called binary digits or bits

Weights
Weight = (Base)
Position

1/2 1/4

1 0 1
2 1
1

0 1
-1
0 -1

-2
-2

Magnitude
Sum of Bit x Weight

1 *2 +0 *2 +1 *2 +0 *2 +1 *2

=(5.25)10 (101.01)2

Formal Notation Groups of bits


4 bits = Nibble 8 bits = Byte

1011 11000101
4 / 47

Hexadecimal Number System Base = 16


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

Weights
Weight = (Base) Position

256

16

1/16 1/256

1 E 5
2
2 1

7 A
-1
-1

Magnitude
Sum of Digit x Weight

0
0

-2
-2

1 *16 +14 *16 +5 *16 +7 *16 +10 *16

=(485.4765625)10 (1E5.7A)16

Formal Notation

5 / 47

The Power of 2 n 0 1 2 3 4 5 6 7 2n 20=1 21=2 22=4 23=8 24=16 25=32 26=64 27=128 n 8 9 10 11 12 20 30 40 2n 28=256 29=512 210=1024 211=2048 212=4096 220=1M 230=1G 240=1T
Mega Giga Tera
6 / 47

Kilo

Addition Decimal Addition 1 + 1 1 5 5 1 5 5 0 = Ten Base Subtract a Base Carry

7 / 47

Binary Addition Column Addition 1 + 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0


= 61 = 23 = 84

(2)10

8 / 47

Binary Subtraction Borrow a Base when needed 1 2 0 1 2 2 0 1 0 1 0 1 0 0 0 1 1 1 2 0 1 1 1 1 0


= 77 = 23 = 54

= (10)2

0 1

9 / 47

Binary Multiplication Bit by bit 1 x 0 1 0 1 1 0 1 0 1 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0


10 / 47

1 0 0 1 0

1 1 0 1

1 0 0

Number Base Conversions


Evaluate Magnitude

Octal (Base 8)
Evaluate Magnitude

Decimal (Base 10)

Binary (Base 2)

Hexadecimal (Base 16)


Evaluate Magnitude
11 / 47

Decimal (Integer) to Binary Conversion Divide the number by the Base (=2) Take the remainder (either 0 or 1) as a coefficient Take the quotient and repeat the division
Example: (13)10
Quotient Remainder Coefficient

13/ 2 = 6 /2= 3 /2= 1 /2=


Answer:

6 3 1 0

1 0 1 1

a0 = 1 a1 = 0 a2 = 1 a3 = 1
LSB
12 / 47

(13)10 = (a3 a2 a1 a0)2 = (1101)2


MSB

Decimal (Fraction) to Binary Conversion


Multiply the number by the Base (=2) Take the integer (either 0 or 1) as a coefficient Take the resultant fraction and repeat the multiplication
Example: (0.625)10
Integer Fraction Coefficient

0.625 * 2 = 1 0.25 * 2 = 0 0.5 *2= 1


Answer:

. . .

25 5 0

a-1 = 1 a-2 = 0 a-3 = 1

(0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2


MSB LSB
13 / 47

Decimal to Octal Conversion


Example: (175)10
Quotient Remainder Coefficient

175 / 8 = 21 / 8 = 2 /8=

21 2 0

7 5 2

a0 = 7 a1 = 5 a2 = 2

Answer:

(175)10 = (a2 a1 a0)8 = (257)8

Example: (0.3125)10
Integer Fraction Coefficient

0.3125 * 8 = 2 0.5 *8= 4


Answer:

. .

5 0

a-1 = 2 a-2 = 4

(0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8


14 / 47

Binary Octal Conversion 8 = 23 Each group of 3 bits represents an octal digit


Example:
Assume Zeros

Octal 0 1 2 3 4 5 6

Binary 000 001 010 011 100 101 110 111

( 1 0 1 1 0 . 0 1 )2

( 2

. 2 )8

Works both ways (Binary to Octal & Octal to Binary)


15 / 47

Binary Hexadecimal Conversion 16 = 24 Each group of 4 bits represents a hexadecimal digit


Example:
Assume Zeros

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

Binary
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

( 1 0 1 1 0 . 0 1 )2

(1

. 4 )16

Works both ways (Binary to Hex & Hex to Binary)


16 / 47

Octal Hexadecimal Conversion Convert to Binary as an intermediate step


Example:

( 2
Assume Zeros

2 )8
Assume Zeros

( 0 1 0 1 1 0 . 0 1 0 )2

(1

4 )16
17 / 47

Works both ways (Octal to Hex & Hex to Octal)

Decimal, Binary, Octal and Hexadecimal


Decimal Binary
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Octal
00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17

Hex
0 1 2 3 4 5 6 7 8 9 A B C D E F
18 / 47

Complements 1s Complement (Diminished Radix Complement)


All 0s become 1s All 1s become 0s Example (10110000)2 (01001111)2 If you add a number and its 1s complement

10110000 + 01001111 11111111


19 / 47

Complements 2s Complement (Radix Complement)


OR

Take 1s complement then add 1 Toggle all bits to the left of the first 1 from the right Example: Number:

10110000 + 1 01010000

10110000

1s Comp.: 0 1 0 0 1 1 1 1

01010000
20 / 47

Negative Numbers Computers Represent Information in 0s and 1s


+ and signs have to be represented in 0s and 1s

3 Systems
Signed Magnitude 1s Complement 2s Complement All three use the left-most bit to represent the sign: 0 1 positive negative
21 / 47

Signed Magnitude Representation Magnitude is magnitude, does not change with sign S
(+3)10 (3)10

Magnitude (Binary)
( 0 0 1 1 )2 ( 1 0 1 1 )2 Sign Magnitude

Cant include the sign bit in Addition 0 0 1 1 (+3)10 + 1011 1110 (3)10 (6)10
22 / 47

1s Complement Representation Positive numbers are represented in Binary 0 1


(+3)10 (3)10

Magnitude (Binary) Code (1s Comp.)


(0 011)2 (1 100)2

Negative numbers are represented in 1s Comp.

There are 2 representations for 0


(+0)10 (0)10 (0 000)2 (1 111)2
23 / 47

1s Complement Range 4-Bit Representation 2 = 16 Combinations 7 Number + 7 23+1 Number +23 1 n-Bit Representation 2n1+1 Number +2n1 1
4

Decimal 1s Comp.
+7 +6 +5 +4 +3 +2 +1 +0 0 1 2 3 4 5 6 7 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000
24 / 47

2s Complement Representation Positive numbers are represented in Binary 0 1


(+3)10 (3)10

Magnitude (Binary) Code (2s Comp.)


(0 011)2 (1 101)2 1111 + 1
25 / 47

Negative numbers are represented in 2s Comp.

There is 1 representation for 0 1s Comp.


(+0)10 (0)10 (0 000)2 (0 000)2

1 0000

2s Complement Range 4-Bit Representation 2 = 16 Combinations 8 Number + 7 23 Number + 23 1 n-Bit Representation 2n1 Number + 2n1 1
4

Decimal 2s Comp.
+7 +6 +5 +4 +3 +2 +1 +0 1 2 3 4 5 6 7 8 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000
26 / 47

Number Representations 4-Bit Example


Unsigned Binary Range 0 N 15 Signed Magnitude -7 N +7
0

1s Comp. -7 N +7
0

2s Comp. -8 N +7
0

Positive Binary Negative

Binary
1

Binary
1 1

Binary

Binary

1s Comp.

2s Comp.
27 / 47

Binary Subtraction Using 1s Comp. Addition Change Subtraction to Addition If Carry = 1 then add it to the LSB, and the result is positive (in Binary) If Carry = 0 then the result is negative (in 1s Comp.) (5)10 (1)10 (+5)10 + (-1)10 0101 + 1110 1 0011 + 0100 +4 (5)10 (6)10 (+5)10 + (-6)10 0101 + 1001 0 1110 1110 1
28 / 47

Binary Subtraction Using 2s Comp. Addition Change Subtraction to Addition If Carry = 1 ignore it, and the result is positive (in Binary) If Carry = 0 then the result is negative (in 2s Comp.) (5)10 (1)10 (+5)10 + (-1)10 0101 + 1111 1 0100 +4 (5)10 (6)10 (+5)10 + (-6)10 0101 + 1010 0 1111 1

29 / 47

Binary Codes Group of n bits


Up to 2n combinations Each combination represents an element of information

Example: Binary code for the seven colors of the rainbow


How many bits are needed?

Which code is not used?

Color Red Orange Yellow Green Blue Indigo Violet

Binary Number 000 001 010 011 101 110 111


30 / 47

Binary Coded Decimal Would it be easy for you if you can replace a decimal number with an individual binary code?
Such as 1910 = Code1 Code9
Decimal 0 1 2 3 4 5 6 7 8 9 BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Binary Coded Decimal (BCD)


Each Decimal Digit is represented by 4 bits (0 9) (10 15) Valid combinations Invalid combinations

31 / 47

Multiple Decimal Digits

Multiple Decimal Digits

351
0011 0101 0001

32 / 47

BCD Addition One decimal digit + one decimal digit


If the result is 1 decimal digit ( 9 ), then it is a simple binary addition Example:

5 8

0101

+ 3

+ 0011 1000

If the result is two decimal digits ( 10 ), then binary addition gives invalid combinations Example:

5 + 5 10

0101 + 0101 1010


33 / 47

0001 0000

BCD Addition If the binary result is greater than 9, correct the result by adding 6 5 + 5 10 0101 + 0101 1010 + 0110 0001 0000
Two Decimal Digits

34 / 47

Weighted Codes The BCD code is a weighted 8,4,2,1 code. 1


8

0
4

0
2

1
1

8 +

0 +

0 +

1 =

35 / 47

Binary Codes for Decimal Digits


There are over 8,000 ways that you can chose 10 elements from the 16 binary numbers of 4 bits. A few are useful: Decimal
0 1 2 3 4 5 6 7 8 9

8,4,2,1
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

8,4,-2,-1
0000 0111 0110 0101 0100 1011 1010 1001 1000 1111

Excess3
0011 0100 0101 0110 0111 1000 1001 1010 1011 1100
36 / 47

Gray Code
The Gray code is unweighted and is not an arithmetic code. One bit changes from one code to the next code Different than Binary Decimal Gray
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000

Binary
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
37 / 47

Gray Code Application


shaft position encoders using Binary code

38 / 47

Gray Code Application


shaft position encoders using Gray code

39 / 47

ASCII Code American Standard Code for Information Interchange


Info
A B

7-bit Code
1000001 1000010

Z a b

. . .

1011010 1100001 1100010

. . .

z @ ? +

. . .

1111010 1000000 0111111 0101011


40 / 47

. . .

Error Detecting Codes Parity


One bit added to a group of bits to make the total number of 1s (including the parity bit) even or odd
4-bit Example 7-bit Example

Even Odd

1 0

0 1 1 1 0 1 1 1

0 1

1 0 0 0 0 0 1 1 0 0 0 0 0 1

Good for checking single-bit errors


41 / 47

Parity
1 0 1 0 1 0 0 0

1 0 1 0 1 Parity Generator

1 0 0 0 1 Parity Checker
42 / 47

Binary Logic Operators


NOT If x = 0 If x = 1 AND If x = 1 AND y = 1 Otherwise OR If x = 1 OR y = 1 Otherwise then z = 1 z = 0
43 / 47

then then

NOT x = 1 NOT x = 0 then z = 1 z = 0

Binary Logic
Truth Tables, Boolean Expressions, and Logic Gates

AND
x 0 0 1 1 y 0 1 0 1 z 0 0 0 1 x 0 0 1 1

OR
y 0 1 0 1 z=x+y z 0 1 1 1

NOT
x 0 1 z 1 0

z=xy=xy

z = x = x

x y

x y

z
44 / 47

Logic Signals Binary 0 is represented by a low voltage (range of voltages) Binary 1 is represented by a high voltage (range of voltages) The voltage ranges guard against noise

Example of binary signals


45 / 47

Switching Circuits

AND

OR

46 / 47

Summary
Binary numbers are made of binary digits (bits) Binary numbers can also be represented in octal and hexadecimal Conversion between number systems Addition, subtraction, and multiplication in binary Signed numbers are represented in 3 codes: signed magnitude, 1s complement, or 2s complement 2s complement code is most important (only 1 representation for zero) Other number codes exits, ASCII code is used to represent characters (such as those on the keyboard)
47 / 47

Anda mungkin juga menyukai