You are on page 1of 26

Digital Logic Design

Dr. M. Najam ul Islam

PhD Electrical Engineering

Lecture 2: Number System

Digital Computer Systems Digital systems consider discrete amounts of data. Examples
26 letters in the alphabet 10 decimal digits Larger quantities can be built from discrete values: Words made of letters Numbers made of decimal digits (e.g. 239875.32) Easy to represent binary values electrically Voltages and currents. Can be implemented using circuits Create the building blocks of modern computers
3

Decimal
Most people today use decimal representation to count. In the
decimal system there are 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example 1: Consider the number 1234. It can be represented as 1*10+ 2*10 + 3*10 + 4*10 Where: 1 is in the thousands place 2 is in the hundreds place 3 is in the tens place 4 is in the ones place. Important note: any number in power of zero is 1, even zero in power of zero is 1.
4

Decimal Example 2: Consider the number 1234.567. It is represented as


1*10+ 2*10 + 3*10 + 4*10+ 5*10-1+ 6*10-2+ 7*10-3

Where:
5 is in the 1/10th place 6 is in the 1/100th place 7 is in the 1/1000th place

Binary The bit is the smallest piece of information that can be


stored in a computer. It can have one of two values 0 or 1. Think of a bit as a switch that can be either on or off.

For example:
Consider the binary number 1101. It can be represented as
1*2+ 1*2 +0*2 + 1*2

In decimal:
8 + 4 + 0 + 1 = 13

Binary Consider the binary number 1101.101. It can be


represented as: 1*2+ 1*2 +0*2 + 1*2 +1*2-1 +0*2-2 +1*2-3 The equivalent decimal number is 13 + 0.5 + 0 + 0.125 = 13.625 To represent larger numbers, we have to group series of bits Nibble - A nibble is a group of four bits - (1101)2 Byte - A byte is a group of eight bits - (11001001)2

Binary Addition Binary addition is very simple. This is best shown in an example of adding two binary
numbers
1
1

carries

1 1 1 0 1 + 1 0 1 1 1 --------------------1 0 1 0 1 0 0

Binary Multiplication Binary multiplication is much the same as decimal


multiplication, except that the multiplication operations are much simpler
0 1 1 1 X 1 0 1 0 ----------------------0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 ----------------------1 1 1 0 0 1 1 0
9

The Growth of Binary Numbers


n 0 1 2n 20=1 21=2 n 8 9 2n 28=256 29=512

2
3 4 5 6 7
10

22=4
23=8 24=16 25=32 26=64 27=128

10
11 12 20 30 40

210=1024
211=2048 212=4096 220=1M 230=1G 240=1T

Octal It can consist of 0,1,2,3,4,5,6,7.

11

Understanding Hexadecimal Numbers Hexadecimal numbers are made of 16 digits:


(0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) How many items does a hex number represent? (3A9F)16 = 3x163 + 10x162 + 9x161 + 15x160 = 15,00710 What about fractions? (2D3.5)16 = 2x162 + 13x161 + 3x160 + 5x16-1 = 723.312510 Note that each hexadecimal digit can be represented with four bits. (1110)2 = (E)16 Groups of four bits are called a nibble. (1110)2
12

Putting It All Together


Binary, octal, and
hexadecimal similar Easy to build circuits to operate on these representations Possible to convert between the three formats

13

Convert an Integer from Decimal to another Base

For each digit position:


Divide decimal number by the base (e.g. 2) The remainder is the lowest-order digit Repeat first two steps until no divisor remains.
Example for (13)10:
Integer Quotient Remainder Coefficient

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

6 3 1 0

+ + + +

a0 = 1 a1 = 0 a2 = 1 a3 = 1

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


14

Convert a Fraction from Decimal to another Base

For each digit position:


Multiply decimal number by the base (e.g. 2) The integer is the highest-order digit Repeat first two steps until fraction becomes zero.
Example for (0.625)10:
Integer Fraction Coefficient

0.625 x 2 = 0.250 x 2 = 0.500 x 2 =

1 0 1

+ + +

0.25 0.50 0

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

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


15

Converting Between Base 16 and Base 2


3A9F16 = (0011 1010 1001 1111)2
3 A 9 F

Conversion is easy!
Determine 4-bit value for each hex digit Note that there are 24 = 16 different values of four bits Easier to read and write in hexadecimal. Representations are equivalent!
16

Converting Between Base 16 and Base 8


3A9F16 = (0011 1010 1001 1111)2
3 A 9 F

352378 =

(011 101 010 011 111)2


3 5 2 3 7

Convert from Base 16 to Base 2 Regroup bits into groups of three starting from right Ignore leading zeros Each group of three bits forms an octal digit.
17

Binary Coded Numbers Binary-coded decimal (BCD) (sometimes called natural


binary-coded decimal, NBCD) is an encoding for decimal numbers in which each digit is represented by its own binary sequence. Its main virtue is that it allows easy conversion to decimal digits for printing or display, and allows faster decimal calculations BCD-encode decimal number using the common encoding, each decimal digit is stored in a four-bit nibble
Decimal BCD 0 0000 1 0001 2 0010 3 0011 4 0100 ----27 0010 0111 83 1000 0011 127 0001 0010

0111
18

BCD Addition

19

The Excess-3 Coding


Excess Code 3 / Excess-3 binary coded decimal (XS-3), also called
biased representation or Excess-N, is a numeral system used on some older computers that uses a pre-specified number N as a biasing value. In XS-3, numbers are represented as decimal digits, and each digit is represented by four bits as the BCD value plus 3 (the "excess" amount):
Decimal 3 2 1 0
20

Excess-3 0000 0001 0010 0011

Decimal 1 2 3 4

Excess-3 0100 0101 0110 0111

Decimal 5 6 7 8

Excess-3 1000 1001 1010 1011

Decimal 9 10 11 12

Excess-3 1100 1101 1110 1111

Gray Coding The reflected binary code, also known as Gray code after
Frank Gray, is a binary numeral system where two successive values differ in only one bit.

The reflected binary code was originally designed to


prevent spurious output from electromechanical switches.

Today, Gray codes are widely used to facilitate error


correction in digital communications such as digital terrestrial television and some cable TV systems

21

Decimal
0 1 2 3 4 5

Binary
0000 0001 0010 0011 0100 0101

Gray-Code.
0000 0001 0011 0010 0110 0111

6
7 8 9 10 11 12 13 14
22

0110
0111 1000 1001 1010 1011 1100 1101 1110 1111

0101
0100 1100 1101 1111 1110 1010 1011 1001 1000

15

More Binary Codes

23

More Binary Codes

24

ASCII Code The American Standard Code for Information Interchange


ASCII is the standard code used for information
interchange and communication between data processing systems, including Internet.

The ASCII character set (or ASCII table) initially


contained 128 (7-bit) coded characters including alphabetic, numeric, graphic and control characters.

25

26

You might also like