0% found this document useful (0 votes)
87 views32 pages

Lecture 1 - Number Systems and Codes

This document provides an overview of a lecture on number systems and codes taught at the University of Zambia. The lecture covers topics such as decimal, binary, hexadecimal, BCD, and Gray code number systems. It also discusses logic fundamentals, Karnaugh maps, logic families, combinational and sequential logic circuits, shift registers, timing diagrams, counters, and introductions to microprocessors, memories, and programmable logic devices. The document lists course prerequisites, time allocation, assessment details, reference textbooks, and course objectives.

Uploaded by

fmwansa806
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views32 pages

Lecture 1 - Number Systems and Codes

This document provides an overview of a lecture on number systems and codes taught at the University of Zambia. The lecture covers topics such as decimal, binary, hexadecimal, BCD, and Gray code number systems. It also discusses logic fundamentals, Karnaugh maps, logic families, combinational and sequential logic circuits, shift registers, timing diagrams, counters, and introductions to microprocessors, memories, and programmable logic devices. The document lists course prerequisites, time allocation, assessment details, reference textbooks, and course objectives.

Uploaded by

fmwansa806
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

The University of Zambia

LECTURE ONE: Number Systems and Codes

Jasper HATILIMA
Department of Electrical and Electronic Engineering, School of Engineering

jasper.hatilima@unza.zm January 2017


jasperhatilima@yahoo.com
Number Systems and Codes
 Decimal, Binary, Hexadecimal, BCD, Gray Code, 2’s Complement, ASCII.

Logic Fundamentals
 Logic gates, Boolean Algebra.

Karnaugh Maps
 Simplification of Boolean expressions, Karnaugh Map rules.

Logic Families:
 Logic Families, TTL, ECL, CMOS.

Combinational Logic:
 Encoder, Decoder, Multiplexer, Demultiplexer, Binary Adder.

Sequential Logic Circuits:


 S-R latch, Flip Flops, Level/Edge Triggering, J-K, D-Flip Flops, State Tables & Diagrams.

 Serial/Parallel In/Out shift registers.

 Timing diagrams, Asynchronous & synchronous systems, Counters.

Introduction to Microprocessors and PLDs:


 Three State Registers.

 Memories: ROM, PROM, EPROM, EEPROM, SRAM, DRAM.

 PLAs, PALs, FPGAs, HDL.

 Microprocessor Architecture, Instruction Set, Assembly language, Simple Computer.

 Programmable Logic Devices: PLAs, PALs, CPLD, FPGAs.

EEE3131 Jasper Hatilima 2017


2
Our main reference text books in this course are
[1] William Kleitz, Digital Electronics: A Practical Approach with VHDL,
9th Ed., 2012, Prentice Hall ISBN-100131714902
[2] Thomas L. Floyd, Digital Fundamentals with PLD Programming, 9th Ed.,
2006, Prentice Hall ISBN-10:0-13-197255-3.
[3] Maini Anil K., Digital Electronics: Principles, Devices and Applications,
2007, John Wiley and Sons Ltd, ISBN 978-0-470-03214-5.
[4] Smith R. J., Dorf R. C., Circuits Devices and Systems, 5th Ed., 2004, John
Wiley and Sons Ltd, ISBN 9971-51-172-X.

There is a lot of data out there on the internet…you can even get information
on how to make holy water from the internet!

EEE3131 Jasper Hatilima 2017 3


Prerequisite
 EEE 3571

Time Allocation
 Lectures 4 hours/week
 Labs 3 hours/week
Assessment
 Assignments /Quizzes 5%
 Labs/Mini-Projects 15%
 Tests 20%
 Final Exam 60%

Class Rules

EEE3131 Jasper Hatilima 2017 4


 To process digital information we use special electronic components that
respond to binary signals.
 To design efficient digital circuits, we also need a special numbering system
and a special algebra to model and analyse the digital circuits.
 In this course, first we examine the binary number system and learn to apply
digital logic theorems to binary relations.
 Eventually, the study of number systems and digital logic theorems will be
applied in understanding the following:
 Digital computers consist of large numbers of logic gates and memory
elements organized to process binary data at high speed.
 Binary data or instructions are stored temporarily in registers. Binary
counters are used in calculations and to keep track of computer
operations.
 Instructions and data are stored at specified locations in memory and can
be retrieved at will.

EEE3131 Jasper Hatilima 2017 5


Objectives of Lecture One
 On completion of the Lectures on Number systems and codes, you should be
able to work in the binary number system as well as the decimal system. In
addition, you should be able to change a number from one base to another.

 The student should also be able to work with the various binary codes that are
used in digital systems and make conversions from one code to another.

EEE3131 Jasper Hatilima 2017 6


 In the decimal number system a quantity is represented by the value and the
position of a digit. The number 503.14 means
1 4
500  0 3  
10 100
 Using powers of 10, this can be rewritten as
5 102  0 101  3 100  1101  4 102

 In other words, 10 is the base and each position to the left or right of the
decimal point corresponds to a power of 10.
 A base 12 or duodecimal system was used by the Babylonians, and we still use
12 in subdividing the foot, the year, and the clock face.
 In representing data by an ON-OFF switch position, there are two possibilities
and the corresponding numbers are 1 and 0.
 In such a binary system, the base is 2 and the decimal number 3 is written as
11 as shown on the next slide:

EEE3131 Jasper Hatilima 2017 7


1 21  1 20  2  1  3
 In electronic logic circuits the numbers 1 and 0 usually correspond to two
easily distinguished voltage levels specified by the circuit designer. For
instance, in TTL (Transistor Transistor Logic), 0 corresponds to a voltage near
zero and 1 to a voltage near +5 V.
Number Conversion
 Binary-to-decimal conversion. In a binary number, each position to the right
or left of the “binary point” corresponds to a power of 2, and each power of 2
has a decimal equivalent.
 To convert a binary number to its decimal equivalent, add the decimal
equivalents of each of the non-zero positions.

EEE3131 Jasper Hatilima 2017 8


 For instance, 110001  25  24  0  0  0  20  32  16  1  49
1
101.01  22  0  20  0  22  4  1   5.25
4
 Decimal-to-binary conversion. A decimal number can be converted to its
binary equivalent by the inverse process, that is, by expressing the decimal
number as a sum of powers of 2.
 An automatic and more popular method is the double-dabble in which integers
and decimals are handled separately.
 To convert a decimal integer to its equivalent, progressively divide the decimal
number by 2, noting the remainders; the remainders taken in reverse order form
the binary equivalent.
 To convert a decimal fraction to its binary equivalent, progressively multiply the
fraction by 2, removing and noting the carries; the carries taken in forward order
form the binary equivalent.

EEE3131 Jasper Hatilima 2017 9


 Example 1
 Convert decimal 28.375 to its binary equivalent.
 Solution. Using the double-dabble method on the
integer,
 The binary equivalent for the integer is thus is 11100.
 Then converting the fraction
0.375  2  0.75 with a carry of 0
0.75  2  1.50 with a carry of 1
0.5  2  1.00 with a carry of 1
 The binary equivalent for the fraction is .011.
 Therefore, 28.375 is equivalent to binary 11100.011.

EEE3131 Jasper Hatilima 2017 10


Binary Arithmetic
 Since the binary system uses the same concept of value and position of the digits
as the decimal system, we expected the associated arithmetic to be similar but
easier.
 The binary multiplication table is very short. For addition in binary, we add
column by column, carrying where necessary into higher position columns.
 In subtraction, we subtract column by column, borrowing where necessary from
higher position columns.
 In subtracting a large number from a smaller, we can subtract the smaller from
the larger and change the sign just as we do with decimals.

EEE3131 Jasper Hatilima 2017 11


Example 2
 Convert the decimal numbers in color to binary and perform the indicated
operations. (SOLUTIONS ARE IN BLACK)
14 1110 13 1101 1010 10
11 1011 10 1010 1101 13
25 11001 3 0011  0011 3

 In multiplication, we obtain partial products using the binary multiplication


table,  0  0  0, 0 1  0, 1 0  0, 11  1 and then add the partial products.
 In division, we perform repeated subtractions just as in long division of
decimals.

EEE3131 Jasper Hatilima 2017 12


Bits, Bytes, and Words
 A single binary digit is called a “bit.” All information in digital system is
represented by a sequence of bits. An 8-bit sequence is called a “byte”; a 4-bit
sequence is a “nibble.”
 The number of bits in the data sequences processed by a given computer is a key
characteristic called the “word length”. Computers handle data in words of 4 to
64 bits.
 An 8-bit microprocessor can receive, process, store, and transmit data or
instructions in form of bytes. Eight bits can be arranged in 28  256
different combinations.
Other Notations
 The number of years in a century can be written 100D or 10010 . In binary
notation this would be written 0  26  25  0  0  22  0  0  01100100B or
011001002 ; the prefix B or subscript 2 is used whenever necessary to avoid
confusion.
EEE3131 Jasper Hatilima 2017 13
Other Notations
 Although 8-bit numbers are easy for computers, they are difficult for humans to
deal with. Hexadecimal number system is used to simply the way binary
number systems are expressed.
 This is a base 16 number system that uses digits 0 to 9, plus the letters of the
alphabet A to F
 This are commonly used in representing memory in microprocessor systems.

EEE3131 Jasper Hatilima 2017 14


Table 1 Number Systems
Decimal Binary Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

EEE3131 Jasper Hatilima 2017 15


Signed Magnitudes
 In binary notation, an n-bit data word can represent the first 2n nonnegative
integers.

 To allow for both positive and negative numbers, the most significant bit (MSB)
can be designated as the sign bit (1 for negative numbers).

EEE3131 Jasper Hatilima 2017 16


Signed Magnitudes
 The lower order bits then represent the magnitude of the number in “straight”
binary notation.
 Although it is used, this arrangement has two disadvantages: the number zero
has two different representations, and two different arithmetic circuits are
required to process positive and negative numbers. And lastly, using it in
arithmetic operations produces results that are undesirable: Try 3-3 and notice
the result.
Two’s Complement Notation
 A better notation for computers, one that is easily implemented in hardware, is
based on the fact that adding the complement of a number is equivalent to
subtracting
n  the
x number.
 A “complement” is that which completes; the “n’s complement” of a number x is
equal to .

EEE3131 Jasper Hatilima 2017 17


 For example, the 10’s complement of 3 is 7. To evaluate 9  3 , i.e., to subtract
3 from 9, we can “add the 10’s complement” of 3 (i.e., 10  3  7 ) to obtain
9  7  16 to yield 6 after discarding the final carry.
 In the decimal system, the 10’s complement of a multi-digit number is easily
found by taking the 9’s complement of each digit (by inspection) and then
adding 1.
 In general, to subtract a two-digit number B from A we use the relationship
A  B  A  100  B   100  A   99  B   1  100 [1]
where  99  B is the 9’s complement.
 In the binary system, arithmetic is simplified if negative numbers are in signed 2’s
complement notation. In this notation, the MSB is the sign bit: 0 for plus, 1 for
minus. To form the 2’s complement of any number, positive or negative:

Form the 1’s complement by changing 1s to 0s and 0s to 1s. Add 1.

EEE3131 Jasper Hatilima 2017 18


 If the result of an arithmetic operation has a 1 sign bit, it is a negative number in
2’s complement notation; to obtain the true magnitude, subtract 1 and form the
1’s complement.

Example 4
a) Obtain the 10’s complement of 15 and 24.
b) Represent 15 and 24 in 8-bit signed 2’s complement notation.
c) Perform 24  15 and 15  24 directly and by complement notation.
Solution
a) Form the 9’s complement of each digit, then add 1:
15  84  1  85 24  75  1  76
b) Form the 1’s complement of each digit, then add 1.

1510  1111  00001111  11110000 +1  11110001  1 1110001


2410  11000  00011000  11100111 +1  11101000  1 1101000

EEE3131 Jasper Hatilima 2017 19


Example 4
c) Solution

EEE3131 Jasper Hatilima 2017 20


Binary-Coded Decimals (BCD)
 For the convenience of humans, computer input/output devices may
accept/provide decimals on the human side and binaries on the computer side.
 The conversion is simplified by coding each decimal digit, that is, replacing it
by the 4-bit binary representation of the digit.
 For example, in the 8421 BCD code 610  0110 , 310  0011 , and
36310  0011 0110 0011 .
 BCD-to-Binary Conversion. A given BCD number can be converted into an
equivalent binary number by first writing its decimal equivalent and then
converting it into its binary equivalent.
 Binary-to-BCD Conversion. The process is the same as the process of BCD-to-
binary conversion executed in reverse order.

EEE3131 Jasper Hatilima 2017 21


Gray Code
 The Gray code was designed by Frank Gray at Bell Labs and patented in 1953.
It is an unweighted binary code in which two successive values differ only by 1
bit. Also called Reflected Binary Code or Cyclic Code.
 Owing to this feature, the maximum error that can creep into a system using
Gray code to encode data is much less than the worst-case error encountered in
the case of straight binary encoding. Table 3 list Gray code equivalents of
decimal numbers 0 – 15.
Table 3 Gray code.
Decimal Binary Gray Decimal Binary Gray
0 0000 0000 8 1000 1100
1 0001 0001 9 1001 1101
2 0010 0011 10 1010 1111
3 0011 0010 11 1011 1110
4 0100 0110 12 1100 1010
5 0101 0111 13 1101 1011
6 0110 0101 14 1110 1001
7 0111 0100 15 1111 1000

EEE3131 Jasper Hatilima 2017 22


Gray Code
 There are various ways by which Gray codes with a given number of bits can be
remembered.
 One such a way is to remember that when the Gray code numbers are
represented in aligned rows, with the digits of each number making up the
columns, the columns from LSB to MSB have 1, 2, 4, 8, …starting zeros and
then each is followed by a pattern of ‘2’ (11, 00, 11, …) in the first LSB column,
then a pattern of ‘4’ (1111, 0000, 1111, …) in the next column and so forth.
 Binary to Gray Code Conversion steps
Step 1. Begin with the most significant bit (MSB). The MSB of the Gray code
equivalent is the same as the MSB of the given binary number.
Step 2. The second MSB in the Gray code number is obtained by adding the
MSB and the second MSB in the binary number and ignoring the carry, if any.
Step 3. The third MSB in the Gray code number is obtained by adding the
second MSB and the third MSB in the binary number, ignore carry.
Step 4. The process continues until we obtain the LSB of Gray code number.

EEE3131 Jasper Hatilima 2017 23


Example 5
 Convert the Binary number 1011 into its Gray code equivalent.
 Solution
Binary 1011
Gray code 1- - -
Binary 1011
Gray code 11
Binary 1011
Gray code 111
Binary 1011
Gray code 1110

EEE3131 Jasper Hatilima 2017 24


Gray Code
 Gray Code to Binary Conversion steps
Step 1. Begin with the most significant bit (MSB). The MSB of the binary
number is the same as the MSB of the Gray code number.
Step 2. The bit next to the MSB (second MSB) in the binary number is obtained
by adding the MSB in the binary number to the second MSB in the Gray code
number and disregarding the carry, if any.
Step 3. The third MSB in the binary number is obtained by adding the second
MSB in the binary number to the third MSB in the Gray code number. Ignored
carry.
Step 4. The process continues until we obtain the LSB of binary number.

EEE3131 Jasper Hatilima 2017 25


Example 6
 Convert the Gray code number 1110 into its binary equivalent.
 Solution
Gray code 1110
Binary 1- - -
Gray code 1110
Binary 10- -
Gray code 1110
Binary 101
Gray code 1110
Binary 1011

EEE3131 Jasper Hatilima 2017 26


Applications of Gray codes
 The Gray code is used in the transmission of digital signals as it minimizes the
occurrence of errors.
 The Gray code is preferred over the straight binary code in angle-measuring
devices i.e. Rotary Encoders.
 The Gray code is used for labeling Karnaugh maps, a graphical technique used
for minimizing of Boolean expressions.
 The use of Gray codes to address program memory in computers minimizes
power consumption. This is due to fewer address lines changing state with
advances in the program counter.
 Gray codes are also useful in genetic algorithms.

EEE3131 Jasper Hatilima 2017 27


Alphanumeric Codes
 When a computer is to handle letters as well as numbers, an alphanumeric code
is used. In the American Standard Code for Information Interchange (ASCII),
seven bits are used to represent all the characters and punctuation marks on a
teletypewriter keyboard plus some control signals.
 Note that, 27  128 combinations of 7 bits. An eighth bit, the MSB, is a parity
bit used in error detection. In even parity convention, the MSB is set so that the
1s in each ASCII character is even; the presence of an odd number of 1s
indicates an error.
 In reference [2], the ASCII code is listed in a table starting from page 28.
 The EBCDIC (Extended Binary Coded Decimal Interchange Code) is another
widely used alphanumeric code, mainly popular with large systems.
 It is an 8-bit code and thus can accommodate up to 256 characters. Reference [2]
has the details.

EEE3131 Jasper Hatilima 2017 28


How many RAM address locations does my computer have?
You will find HEX numbers extensively used in computer memory description.
The procedure below shows how you can check the memory allocations in
Windows:
 Go to “Device Manage” or “devmgmt.msc” in search bar.

 Go to “View” and then “Resources by Connection”

 Expand the “Computer Name” node and

 Expand the “Memory” node

 Then go ahead and check the various allocations under “PCI Bus”.

EEE3131 Jasper Hatilima 2017 29


The following points to remember:
 Why digital? Compare digital and analog.

 To change an analog signal to digital, ADC is used. Read about ADC (You
will actually cover it in EEE 3571).

 Once signal is in digital form, it is represented by binary code. Conversions


between the various number systems (Binary, Decimal, Hexadecimal).

 Binary within itself has various codes (BCD, Gray Code, many others).
Applications/Advantages of Gray code?

 How are negative numbers represented in binary? Is there any effect on the
range and values of numbers that can be presented by using signed
representation?

 The above point brings in the concept of data types in statically typed
programming languages as exemplified by next slide:
EEE3131 Jasper Hatilima 2017 30
NUMBER OF RANGE (UNSIGNED) RANGE (SIGNED)
BITS 0 to (2n – 1) - (2n-1) to (2n-1 - 1)
4 0 to 15 -8 to 7
8 0 to 255 -128 to 127
16 0 to 65, 535 -32, 768 to 32, 767
32 0 to 4.29 billion -2.15 billion to 2.15 billion

Below is a four-bit number range (-8 to 7) to show how the negative


numbers are stored (2’s complement) in computer memory:
This subrange is just like a piece cut from after the last positive value (here)
and swapped with the positive subrange…

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

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

EEE3131 Jasper Hatilima 2017 31


Dzikomo
Next: Logic Fundamentals

EEE3131 Jasper Hatilima 2017 32

You might also like