Digital Electronics Module 01
Digital Electronics Module 01
Digital Electronics Module 01
1 www.learnabout-electronics.org
Digital Electronics
1.0 Introduction to Number Systems
Using the decimal system it is easy to count up to ten fingers, using just the fingers on two hands. In
northern Britain farmers, for centuries, used an ancient Celtic counting system, based on 20 (also
called a score), to count their animals, and its use still persisted even into the second half of the
twentieth century.
The binary system, based on 2, is just another special number system, and is used by digital
electronic devices because digital circuits work on an electrical ‘on or off’ two state system, a
number system based on 2 is therefore much easier for electronic devices to use. However binary is
not a natural choice for human counting or calculation.
This module explains how binary, and some other number systems used in electronics work, and
how computers and calculators use different forms of binary to carry out calculations.
The reason for these differences is because each system has a different base, and the column values
in each system increase by multiples of the base number as columns are added to the left.
Table 1.1.1
Some column values of different number systems
Decimal 1000 100 10 1
Binary 8 4 2 1
Octal 512 64 8 1
Hexadecimal 4096 256 16 1
Because this module describes several different number systems, it is important to know which
system is being described. Therefore if there is some doubt which system a number is in, the base of
the system, written as a subscript immediately after the value, is used to identify the number system.
For example:
1010 represents the decimal value ten. (1 ten + 0 units)
102 represents the binary value two. (1 two + 0 units)
108 represents the octal value eight. (1 eight + 0 units)
1016 represents the hexadecimal value sixteen. (1 sixteen + 0 units)
The System Radix
The base of a system, more properly called the RADIX, is the number of different values that can
be expressed using a single digit. Therefore the decimal system has a radix of 10, the octal system
has a radix of 8, hexadecimal is radix 16, and binary radix 2.
The range of number values in different number systems is shown in Table 1.1.2, Notice that
because the hexadecimal system must express 16 values using only one column, it uses the letters A
B C D E & F to represent the numbers 10 to 15.
Table 1.1.2
Decimal Binary Octal Hexadecimal
(Radix 10) (Radix 2) (Radix 8) (Radix 16)
0 0 0 0
1 1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8
9 9
A
B
C
D
E
F
= 456.210
Each digit in the number is multiplied by the system radix raised to a power depending on its
position relative to the radix point. This is called the EXPONENT. The digit immediately to the
left of the radix point has the exponent 0 applied to its radix, and for each place to the left, the
exponent increases by one. The first place to the right of the radix point has the exponent -1 and so
on, positive exponents to the left of the radix point and negative exponents to the right.
This method of writing numbers is widely used in electronics with decimal numbers, but can be
used with any number system. Only the radix is different.
Hexadecimal exponents 98.216 = (9 x 161) + (8 x 160) + (2 x 16-1)
Octal exponents 56.28 = (5 x 81) + (6 x 80) + (2 x 8-1)
Binary Exponents 10.12 = (1 x 21) + (0 x 20) + (1 x 2-1)
When using your calculator for the above examples you may find that it does not like radix points in
anything other than decimal mode. This is common with many electronic calculators.
Floating Point Notation
If electronic calculators cannot use radix points other than in decimal, this could be a problem.
Fortunately for every problem there is a solution. The radix exponent can also be used to eliminate
the radix point, without altering the value of the number. In the example below, see how the value
remains the same while the radix point moves. It is all done by changing the radix exponent.
102.610 = 102.6 x 100 = 10.26 x 101 = 1.026 x 102 = .1026 x 103
The radix point is moved one place to the left by increasing the exponent by one.
It is also possible to move the radix point to the right by decreasing the exponent. In this way the
radix point can be positioned wherever it is required - in any number system, simply by changing
the exponent. This is called FLOATING POINT NOTATION and it is how calculators handle
decimal points in calculations.
Normalised Form
By putting the radix point at the front of the number, and keeping it there by changing the exponent,
calculations become easier to do electronically, in any radix.
Electronic storage of numbers
A number written (or stored) in this way, with the radix point at the left of the most significant digit
is said to be in NORMALISED FORM. For example .110112 x 23 is the normalised form of the
binary number 110.112. Because numbers in electronic systems are stored as binary digits, and a
binary digit can only be 1 or 0, it is not possible to store the radix point within the number.
Therefore the number is stored in its normalised form and the exponent is stored separately. The
exponent is then reused to restore the radix point to its correct position when the number is
displayed.
In electronics systems a single binary digit is called a bit (short for Binary DigIT), but as using a
single digit would seriously limit the maths that could be performed, binary bits are normally used
in groups.
4 bits = 1 nibble
8 bits = 1 byte
Multiple bytes, such as 16 bits, 32 bits, 64 bits are usually called ‘words’, e.g. a 32 bit word. The
length of the word depends on how many bits can be physically handled or stored by the system at
one time.
4 Bit Binary Representation
Table 1.1.4
MSB 4 Bit Binary LSB
Decimal
23 = 8 22 = 4 21 = 2 20 = 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1
When a number is stored in an electronic system, it is stored in a memory location having a fixed
number of binary bits. Some of these memory locations are used for general storage whilst others,
having some special function, are called registers. Wherever a number is stored, it will be held in
some form of binary, and must always have a set number of bits. Therefore a decimal number such
as 13, which can be expressed in four binary bits as 11012 becomes 000011012 when stored in an
eight-bit register. This is achieved by adding four NON-SIGNIFICANT ZEROS to the left of the
most significant ‘1’ digit.
Using this system, a binary register that is n bits wide can hold 2n values.
Therefore an 8 bit register can hold 28 values = 256 values (0 to 255)
A 4 bit register can hold 24 values = 16 values (0 to 15)
HOW MANY VALUES CAN A 16 BIT REGISTER HOLD__________________________?
Filling the register with non-significant zeros is fine - if the number is smaller than the maximum
value the register will hold, but how about larger numbers? These must be dealt with by dividing
the binary number into groups of 8 bits, each of which can be stored in a one-byte location, and
using several locations to hold the different parts of the total value. Just how the number is split up
depends on the design of the electronic system involved.
Summary:
• Electronic systems may use a variety of different number systems, (e.g. Decimal, Hexadecimal, Octal,
Binary).
• The number system in use can be identified by its radix (10, 16, 8, 2).
• The Exponent is the system radix raised to a power dependent on the column value of a particular digit
in the number.
• In Floating Point Notation the Radix Point can be moved to a new position without changing the value of
the number if the Exponent of the number is also changed.
• In Normalised Form the radix point is always placed to the left of the most significant digit.
• When numbers are stored electronically they are stored in a register holding a finite number of digits; if
the number stored has less digits than the register, non-significant zeros are added to fill spaces to the left
of the stored number. Numbers containing more digits than the register can hold are broken up into
register sized groups and stored in multiple locations.
It is often necessary to convert values written in one number system to another. The simplest way is
to reach for your calculator or use a conversion app. from the web. That is fine, but converting a
number in this way does not help you to understand the way each number system works and how
different systems are related. The purpose of this module is to explain just that, and to get you to
carry out some simple conversions so that you can not only convert between number systems, but
also understand how the conversion process works. There are various ways to tackle conversions
without a calculator; once the conversion methods are learned, the only skills needed are the ability
to multiply and divide, and to add together a few numbers.
Conversion from any system to decimal.
The number of values that can be expressed by a single digit in any number system is called the
system radix, and any value can be expressed in terms of its system radix.
Octal to Decimal
For example the system radix of octal is 8, since any of the 8 values from 0 to 7 can be written as a
single digit.
Decimal to Octal
The same process works to convert decimal to octal, but this time the
system radix is 8:
Example 1.2.2 Decimal
Therefore 5710 = 718
to Octal Conversion
Decimal to Hexadecimal
It also works to convert decimal to hexadecimal, but now the radix is 16:
Therefore 5710 = 3916
Example 1.2.3 Decimal to
Hexadecimal Conversion
Numbers with Fractions
It is very common in the decimal system to use fractions; that is any decimal number that contains a
decimal point, but how can decimal numbers, such as 34.62510 be converted to binary fractions?
In electronics this is not normally done, as binary does not work well with fractions. However as
fractions do exist, there has to be a way for binary to deal with them. The method used is to get rid
of the radix (decimal) point by NORMALISING the decimal fraction using FLOATING POINT
arithmetic. As long as the binary system keeps track of the number of places the radix point was
moved during the normalisation process, it can be restored to its correct position when the result of
the binary calculation is converted back to decimal for display to the user.
However, for the sake of completeness, here is a method for converting decimal fractions to binary
fractions. By carefully selecting the fraction to be converted, the system works, but with many
numbers the conversion introduces inaccuracies, a good reason for not using binary fractions in
electronic calculations.
Converting the Decimal Integer to Binary
The radix point splits the number into two parts; the part to the
left of the radix point is called the INTEGER. The part to the right
of the radix point is the FRACTION. A number such as 34.62510
is therefore split into 3410 (the integer), and .62510 (the fraction).
To convert such a fractional decimal number to any other radix,
the method described above is used to covert the integer.
Example 1.2.4 Converting
So 3410 = 1000102 the Integer to Binary
For the converted value just read the carry column from top to bottom.
So 0.62510 = .1012
Therefore the complete conversion shows that 34.62510 = 100010.1012
However, with binary, there is a problem in using this method, .625 converted easily but many
fractions will not. For example if you try to convert .626 using this method you would find that the
binary fraction produced goes on to many, many places without a result of exactly 000 being
reached.
With some decimal fractions, using the above method will produce carries with a repeating pattern
of ones and zeros, indicating that the binary fraction will carry on infinitely. Many decimal fractions
can therefore only be converted to binary with limited accuracy. The number of places after the
radix point must be limited, to produce as accurate an approximation as required.
Quick Conversions
The most commonly encountered number systems are binary and hexadecimal, and a quick method
for converting to decimal is to use a simple table showing the column weights, as shown in Tables
1.2.1a and 1.2.1b.
Converting Binary to Decimal
To convert from binary to decimal write down the binary number giving each column its correct
‘weighting’ i.e. the value of the columns, starting with a value of one for the right hand (least
significant column − or LEAST SIGNIFICANT BIT) column. Giving each column twice the value
of the previous column as you move left.
Table 1.2.1a
Bit 27 26 25 24 23 22 21 20
Value (weighting) of each bit 128 64 32 16 8 4 2 1
8 Bit Binary 0 1 0 0 0 0 1 1
Example:
To convert the binary number 010000112 to decimal, write down the binary number and assign a
‘weighting’ to each bit as in Table 1.2.1a
Now simply add up the values of each column containing a 1 bit, ignoring any columns containing
0.
Applying the appropriate weighting to 01000011 gives 256 + 64 + 2 + 1 = 67
Now try some conversions yourself. Use pencil and paper to practice the method, rather than just
finding the answer.
Convert:
110100112 to decimal.
101110112 to decimal.
34F216 to decimal.
FFFF16 to decimal.
Check your answer by converting the decimal back to binary or hexadecimal.
Don’t use your calculator - you need to learn the method, not just the answer!
Binary and Hexadecimal
Converting between binary and hexadecimal is a much simpler process; hexadecimal Table 1.2.2
is really just a system for displaying binary in a more readable form. Binary Hex.
0000 0
Binary is normally divided into Bytes (of 8 bits) it is convenient for machines but 0001 1
quite difficult for humans to read accurately. Hexadecimal groups each 8-bit byte 0010 2
into two 4-bit nibbles, and assigns a value of between 0 and 15 to each nibble. 0011 3
Therefore each hexadecimal digit (also worth 0 to 15) can directly represent one 0100 4
binary nibble. This reduces the eight bits of binary to just two hexadecimal 0101 5
characters. 0110 6
0111 7
For example:
1000 8
111010012 is split into 2 nibbles 11102 and 10012 then each nibble is assigned a 1001 9
hexadecimal value between 0 and F. 1010 A
1011 B
The bits in the most significant nibble (11102) add up to 8+4+2+0 = 1410 = E16 1100 C
1101 D
The bits in the least significant nibble (10012) add up to 8+0+0+1 = 910 = 916 1110 E
1111 F
Therefore 111010012 = E916
Converting hexadecimal to binary of course simply reverses this process.
• Overflow.
Example:
Binary addition is carried out just like decimal, by adding up the
columns, starting at the right and working column by column towards
Fig. 1.3.2 Simple
the left.
Binary Addition
Just as in decimal addition, it is sometimes necessary to use a ‘carry’,
and the carry is added to the next column. For example, in Fig.
1.3.3 when two ones in the right-most column are added, the result
is 210 or 102, the least significant bit of the answer is therefore 0 and
the 1 becomes the carry bit to be added to the 1 in the next column.
Table 1.4.1
For example: Binary Decimal Signed Binary
Although signed binary can represent positive and negative numbers, if it is used for calculations,
some special action would need to be taken, depending on the sign of the numbers used, and how
the two values for 0 are handled, to obtain the correct result. Whilst signed binary does solve the
problem of REPRESENTING positive and negative numbers in binary, and to some extent carrying
out binary arithmetic, there are better sign and magnitude systems for performing binary arithmetic.
These systems are the ONES COMPLEMENT and TWOS COMPLEMENT systems, which are
described in Number Systems Module 1.5.
This is not good enough, however there is a system that overcomes this difficulty and allows correct
operation using both positive and negative numbers. This is the Twos Complement system.
Twos Complement Notation
Twos complement notation solves the problem of the relationship between positive and negative
numbers, and achieves accurate results in subtractions.
To perform binary subtraction the twos complement system uses the technique of complementing
the number to be subtracted. In the ones complement system this produced a result that was 1 less
than the correct answer, but this could be corrected by using the ‘end around carry’ system. This
still left the problem that positive and negative versions of the same number did not produce zero
when added together.
The twos complement system overcomes both of these problems by simply adding one to the ones
complement version of the number before addition takes place. The process of producing a
negative number in Twos Complement Notation is illustrated in Table 1.5.2.
Table 1.5.2
Producing a Twos Complement Negative Number
+5 in 8-bit binary (or 8-bit Signed Binary) is 00000101
Complementing to produce the Ones Complement 11111010
With 1 added 1
So -5 in Twos Complement is 11111011
With numbers electronically stored in their twos complement form, subtractions can be carried out
more easily (and faster) as the microprocessor has simply to add two numbers together using nearly
the same circuitry as is used for addition.
6 − 2 = 4 is the same as (+6) + (−2) = 4
Note: When working with twos complement it is important to write numbers in their full 8 bit
form, since complementing will change any leading 0 bits into 1 bits, which will be included in
any calculation. Also during addition, carry bits can extend into leading 0 bits or sign bits, and
this can affect the answer in unexpected ways.
Microprocessors deal with this problem by using a special register called a status register, flag
register or conditions code register, which automatically flags up any problem such as an overflow
or a change of sign that occurs. It also provides other information useful to the programmer, so that
whatever problem occurs; corrective action can be taken by software, or in many cases by firmware
permanently embedded within the microprocessor to deal with a range of math problems.
Whatever word length the microprocessor is designed to handle however, there must always be a
limit to the word length, and so the programmer must be aware of the danger of errors similar to
that described in Fig. 1.5.7.
A typical flag register is illustrated in Fig. 1.5.8 and
consists of a single 8-bit storage register located
within the microprocessor, in which some bits may
be set by software to control the actions of the
Fig. 1.5.8 Typical 8-bit Flag Register
microprocessor, and some bits are set automatically
by the results of arithmetic operations within the microprocessor.
Typical flags for an 8-bit microprocessor are listed below:
Bit 0 (C) (set by arithmetic result) = 1 Carry has been created from result msb.
Bit 1 (Z) (set by arithmetic result) = 1 Calculation resulted in 0.
Bit 2 (I) (set by software) 1 = Interrupt disable (Prevents software interrupts).
Bit 3 (D) (set by software) 1 = Decimal mode (Calculations are in BCD).
Bit 4 (B) (set by software) 1 = Break (Stops software execution).
Bit 5 (X) Not used on this particular microprocessor.
Bit 6 (V) (set by arithmetic result) = 1 Overflow has occurred (result too big for 8 bits).
Bit 7 (N) (set by arithmetic result) = 1 Negative result (msb of result is 1).
It seems therefore, that the only math that microprocessors can do is to add together two numbers of
a limited value, and to complement binary numbers. Well at a basic level this is true, however there
are some additional tricks they can perform, such as shifting all the bits in a binary word left or
right, as a partial aid to multiplication or division. However anything more complex must be done
by software.
Subtraction and Division
While addition and subtraction can be achieved by adding positive and negative numbers as
described above, this does not include the other basic forms of mathematics, multiplication and
division. Multiplication in its simplest form can however be achieved by adding a number to itself a
number of times, for example, starting with a total of 0, if 5 is added to the total three times the new
total will be fifteen (or 5 x 3). Division can also be accomplished by repeatedly subtracting (using
add) the divisor from the number to be divided until the remainder is zero, or less than the divisor.
Counting the number of subtractions then gives the result, for example if 3 (the divisor) is
repeatedly subtracted from 15, after 5 subtractions the remainder will be zero and the count will be
5, indicating that 15 divided by 3 is exactly 5.
There are more efficient methods for carrying out subtraction and division using software, or extra
features within some microprocessors and/or the use of embedded maths firmware.
BCD Codes
BCD8421 code is so called because each of the four bits is given a ‘weighting’ according to its
column value in the binary system. The least significant bit (lsb) has the weight or value 1, the next
bit, going left, the value 2. The next bit has the value 4, and the most significant bit (msb) the value
8, as shown in Table 1.6.1.
So the 8421BCD code for the decimal number 610 is 01108421. Check this from Table 1.6.1.
For numbers greater than 9 the system is extended by using a second block of 4 bits to represent
tens and a third block to represent hundreds etc.
2410 in 8 bit binary would be 00011000 but in BCD8421 is 0010 0100.
99210 in 16 bit binary would be 00000011111000002 but in BCD8421 is 1001 1001 0010.
Therefore BCD acts as a half way stage between binary and true decimal representation, often
preparing the result of a pure binary calculation for display on a decimal numerical display.
Although BCD can be used in calculation, the values are not the same as pure binary and must be
treated differently if correct results are to be obtained. The facility to make calculations in BCD is
included in some microprocessors.
One of the main drawbacks of BCD is that, because sixteen values are available from four bits, but
only ten are used, there are several redundant values whichever BCD system is used. This is
wasteful in terms of circuitry, as the fourth bit (the 8s column) is under used.
Try some simple conversions between Decimal and BCD8421
32110 to BCD8421
6523110 to BCD8421
001101110110 BCD8421 to decimal.
0011001011000110 BCD8421 to decimal.
Display Decoder/Drivers
Depending on the type of display some further code conversion
may also be needed. One popular type of decimal display is the 7
segment display used in LED and LCD numerical displays,
where any decimal digit is made up of 7 segments arranged as a
figure 8, with an extra LED or LCD dot that can be used as a
decimal point, as shown in Fig 1.6.1. These displays therefore
require 7 inputs, one to each of the LEDs a to g (the decimal
point is usually driven separately). Therefore the 4-bit output in
Fig. 1.6.1 Seven
BCD must be converted to supply the correct 7 bit pattern of
Segment Display
outputs to drive the display.
The four BCD bits are usually converted (decoded) to provide the
correct logic for driving the 7 inputs of the display by integrated
circuits such as the HEF4511B BCD to 7-segment decoder/driver
from NXP Semiconductors and the 7466 BCD to 7-segment
decoder.
Question
BCD to 7 segment decoders
implement a logic truth table such as
the one illustrated in Table 1.6.2.
There are different types of display
implemented by different types of
decoder, notice in table 1.6.2 that
some of the output digits* may be
either 1 or 0 (depending on the IC
used). Why would this be, and what
effect would it have on the display?
Gray Code
Binary codes are not only used for
data output. Another special binary
code that is extensively used for
reading positional information on
mechanical devices such as rotating
shafts is Gray Code. This is a 4-bit
code that uses all 16 values, and as
the values change through 0-1510
the code’s binary values change
only 1 bit at a time, (see Table
1.6.4). The binary values are
encoded onto a rotating disk (Fig.
1.6.3) and as it rotates the light and
dark areas are read by optical
sensors.
As only one sensor sees a change at any one time, this reduces errors that may be created as the
sensors pass from light to dark (0 to 1) or back again. The problem with this kind of sensing is that
if two or more sensors are allowed to change simultaneously, it cannot be guaranteed that the data
from the sensors would change at exactly the same time. If this happened there would be a brief
time when a wrong binary code may be generated, suggesting that the disk is in a different position
to its actual position. The one bit at a time feature of Gray Code effectively eliminates such errors.
Notice also that the sequence of binary values also rotates continually, with the code for 15
changing back to 0 with only 1 bit changing. With a 4 bit coded disk as illustrated in Fig. 1.6.3, the
position is read every 22.5° but with more bits, greater accuracy can be achieved.
2.
Which of the following decimal numbers is equivalent to the highest value that can be held in an 8-
bit binary register using unsigned binary?
a) 127
b) 256
c) 65536
d) 255
3.
What is the decimal equivalent of the number 3A16?
a) 58
b) 39
c) 310
d) 49
4.
Refer to Fig. 1.7.1.Which of the tables correctly describes the rules
of binary addition?
a)
b)
c)
d)
5. Fig. 1.7.1
What is the 8 bit unsigned binary result of 5610 − 3110?
a) 000110012
b) 000101012
c) 001100012
d) 000011012
6.
What is the result of adding 710 and −410 using 8 bit signed binary notation?
a) 100000112
b) 000010112
c) 100010112
d) 000000112
7.
What is the widest range of decimal numbers that can be written in 8 bit signed binary notation?
a) −127 to +127
b) −0 to +256
c) −128 to +128
d) −256 to −1
8.
End around carry is used to correct the result of additions in which of the following number
systems?
a) 8 bit Signed Binary.
b) 8 bit Ones Complement.
c) 8 bit Twos Complement.
d) Excess 3 BCD
9.
Which of the following 4 bit Excess 3 numbers is equivalent to 510?
a) 1101bcdxs3
b) 0010bcdxs3
c) 1000bcdxs3
d) 1010bcdxs3
10.
Which of the following Twos Complement binary numbers is equivalent to −7510?
a) 11001011
b) 01001100
c) 11001100
d) 10110101