EEE2046 Week 1 Notes Chapter 1 Number Systems
EEE2046 Week 1 Notes Chapter 1 Number Systems
Number Systems
1.1 Background
The majority of modern consumer and industrial electronics contain some form of embedded
system. An embedded system is a specialised digital computer which is incorporated into a larger
device or system. These digital circuits have a dedicated role within the device and are typically
designed using one or more microcontrollers, microprocessors or digital signal processors as well
as a host of external peripheral devices. They differ from general purpose computers, such as the
PC, in that they are designed to perform an exclusive function which means that they are often
smaller, have lower power consumption and can have more predictable run-time behaviour. To be
able to design these complex digital circuits, we first need to understand what a digital system is
and how the basic digital building blocks work. This is what we will be examining in detail in the
next few chapters.
A fundamental aspect of perception is the ability to observe, measure and record information to
create or update models of phenomena over time. These models can then be used to understand
the behaviour of the system. Why is this important? If we want to understand past or predict
future behaviour, control the system in some way, communicate its state or build upon it, we
need to have this information. This process of collecting and interpreting information forms the
backbone of all science and engineering.
One example of a biological perception system is the brain. It is very good at processing and
interpreting the information that is obtained from the biological sensors in our body, such as the
eyes or ears and then using this information to reduce the uncertainty in our models of the world
around us. We are also able to create artificial systems which are able to perform aspects of
this process and as engineers we are involved in the analysis and design of these systems. How to
collect, represent and store the information depends on what is being observed and the environment
that the perception system is in.
Most real-world signals are continuous or analogue in nature, for example the temperature in
the room or the potential difference between two points in a circuit. We can describe the time-
varying behaviour of these variables using a continuous mathematical function such as a differential
equation. However if we want to represent the value of this signal at some point in time, we can
1
EEE2046F/EEE2050F Course Notes
approximate and ’encode’ the information in its current state using a discrete value or set of
symbols. If these values have a finite number of states, the system is known as a digital or discrete
system. Examples of digital systems are the 26 letters in the English alphabet or the 10 decimal
numbers [9] [5]. Another example of a digital representation is the binary system, which forms the
basis of all modern computing.
The standard measure in information theory for the amount of information, I in bits in a message,
M can be calculated using Equation 1.1, developed by Claude Shannon in Bell Labs in 1948 [12].
Any logarithmic base can be used in the equation to calculate the basic unit of information for a
particular symbolic set and will depend on the number of states or discrete values in that set. We
will however only consider the two state binary set in this book when considering the amount of
information in a message.
We will now consider the three main symbolic representations or number systems used in electronic
digital systems, followed by a look at the physical hardware, the digital logic gates, which can be
used to manipulate their values. We will then consider the real-world limitations of these gates.
For the most part, we only use one type of number representation in our daily lives, the decimal
system and are completely familiar with both its interpretation and arithmetic. However there are
many number systems available to us and in some cases it is better to use these to represent
information, as we will see in the digital world. A number system is a consistent way of writing
and representing numbers using a combination of predefined symbols.
The decimal system is based on the Hindu-Arabic numeral system which is a type of positional
number notation. A positional number system uses the same set of symbols in different positions
in the numeral to represent different orders of magnitude. For example the decimal number 21
is represented by the number 2 in the tens position and the number 1 in the units position. No
matter how large the number we want to generate, we will still use the same 10 base symbols in
a particular sequence. So if you now want to represent a larger number say 321, we simply add
another symbol in the hundreds column of the numeral and so on.
This is completely different to a non-positional notation, such as Roman numeral system. Lets
consider the decimal number 4 in Roman numerals, IV. If we now consider the next two decimal
numbers in the sequence, 5 and 6, they are represented by V and VI respectively. We can see
the positions of the individual digits in the Roman numeral change which makes representation,
interpretation and calculations with these numbers complex.
Positional notation revolutionised arithmetic and due to its simplicity the decimal system is now
one of the most common number systems in use today.
We will now consider the three most common number systems used in the digital world so that we
can understand both their representation and how to perform basic arithmetic using these numbers.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 2 of 238
EEE2046F/EEE2050F Course Notes
The decimal number system is base-10 positional number system and uses the ten decimal digits
D 2 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Numbers are represented using a combination of these symbols and
can be interpreted as in the Example 1.1:
Example 1.1
We can see that each position in the numeral represents the symbol in that position multiplied
by 10i where i represents the index1 in the numeral. This rule applies to all positional number
systems, however as we will see in other number systems, the base of the power changes.
As we are familiar with the manipulation of decimal numbers we will not discuss this in detail in
this book. However we will learn how to convert between the decimal, binary and hexadecimal
number systems in the following sections.
The binary number system is a base-2 positional number system, and only uses two symbols to
represent all numerals. These symbols are 1 and 0 and are known as bits which is short for binary
digit. Lets look at an example.
Example 1.2
11012 = (1 ⇥ 23 ) + (1 ⇥ 22 ) + (0 ⇥ 21 ) + (1 ⇥ 20 )
= (1 ⇥ 8) + (1 ⇥ 4) + (0 ⇥ 2) + (1 ⇥ 1)
= (810 ) + (410 ) + (010 ) + (110 )
= 1310
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 3 of 238
EEE2046F/EEE2050F Course Notes
Table 1.1: 8-bit binary number. The most significant bit (MSB) in a binary digit
represents the largest power of 2 in the sequence (b7 ⇥ 27 ), while the least significant
bit (LSB) represents the lowest power of 2 in the sequence (b0 ⇥ 20 ).
7 6 5 4 3 2 1 0
1 1 0 1 0 0 1 0
MSB LSB
Certain powers of two have special meanings in digital systems and we can see some of them in
table 1.2.2
Table 1.2: Binary prefixes. These powers have special names in digital system as
defined by the IEC International System of Quantities (ISO/IEC 80000).
We will now see how to convert a decimal number into a binary value. We can approach this
process using two algorithms: (a) the sum of weights method or (b) the repeated division by 2
method. We will first consider the Sum of Weights method.
2
Note: Commonly 210 , 220 and 230 are also called a kilobyte (KB) (1024 bytes), a megabyte (MB) (10242
bytes) and a gigabyte (GB) (10243 bytes). This notation is often used for RAM devices and by certain operating
systems to indicate storage size, although these are not official units as defined by the ISO/IEC 80000 standard. Be
aware of which is being used in which context.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 4 of 238
EEE2046F/EEE2050F Course Notes
Example 1.3
Convert the decimal number 23510 (D) to binary (B) using the Sum of Weights method.
To start we need to find out the minimum number of bits needed to represent the decimal
value. We can do this as follows:
1. Calculate the minimum number of bits (m) that are needed to represent the decimal
number (D) and find the value of the index of the most significant bit (bn ) in the binary
sequence (B), where n = m 1 and B = bn bn 1 . . . b1 b0 .
n = roundup(log2 (D + 1)) 1
= roundup(log2 (235 + 1)) 1
= roundup(log2 (236)) 1
= roundup(7.883) 1
=8 1
=7
Therefore 2n = 27 = 128 is the largest power of two that will divide into 23510 and
produce a quotient that is greater than or equal to 1.
2. Divide 235 by 27 and find the truncated quotient (qi ) (rounded down), this will be the
binary digit at position i .
bi =truncate(di /2i )
=truncate(235/27 )
=truncate(235/128)
=truncate(1.835)
=1
7
23510 = Â bi 2i
i=0
=(1 ⇥ 27 ) + (b6 ⇥ 26 )+
(b5 ⇥ 25 ) + (b4 ⇥ 24 )+
(b3 ⇥ 23 ) + (b2 ⇥ 22 )+
(b1 ⇥ 21 ) + (b0 ⇥ 20 )
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 5 of 238
EEE2046F/EEE2050F Course Notes
di 1 = di bi ⇥ 2i
= 235 (1 ⇥ 27 )
= 235 (1 ⇥ 128)
= 107
This value will now become the new value of di for the calculation of the next binary
digit in the sequence at i = n 1.
4. We will now find the binary value of all 8 binary digits from left to right. Note if the
number di is less than that current power of 2 (2i ) it will produce a quotient of 0 the
current value of di will be carried to the next step. Now repeat steps 1 to 3 until you
have a value for all the bits in the sequence.
23510 = (1 ⇥ 27 ) + (1 ⇥ 26 ) + (1 ⇥ 25 ) + (0 ⇥ 24 ) + (1 ⇥ 23 ) + (0 ⇥ 22 ) + (1 ⇥ 21 ) + (1 ⇥ 20 )
= (1 ⇥ 128) + (1 ⇥ 64) + (1 ⇥ 32) + (0 ⇥ 16) + (1 ⇥ 8) + (0 ⇥ 4) + (1 ⇥ 2) + (1 ⇥ 1)
5. Combine the binary digits together, keeping the original order to represent the binary
number B:
B =b7 b6 b5 b4 b3 b2 b1 b0
=(11101011)2
6. It is also often useful to write this process out using a table (Table 1.3), where each
column represents one iteration of the process.
Table 1.3: Conversion from decimal to binary using the Sum of Weights method.
Start at the MSB (i = n) and use the Sum of Weights Algorithm (Algorithm 1.1) to
find the binary digit (bi ) at this position. Update the value of di based on the whether
di 2i and move along the table finding each binary digit until you reach the LSB
(i = 0).
i 7 6 5 4 3 2 1 0
di 235 107 43 11 11 3 3 1
2i 128 64 32 16 8 4 2 1
di ÷ 2i 1.84 1.67 1.34 0.69 1.38 0.75 1.5 1
bi 1 1 1 0 1 0 1 1
As we can see in Example 1.3, there is a trade-off between the simplicity of only needing to using
0’s and 1’s to represent values and length of the numeral. All complex digital information from the
text in a PDF to digital images to computer code can be represented as a series of 0’s and 1’s.
How we interpret these 0’s and 1’s is dependent on the application. This is hugely powerful and
we will learn in this book how we can use this to control digital electronic hardware at a low-level.
We will now consider an alternative algorithm to convert a decimal value to binary, the Repeated
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 6 of 238
EEE2046F/EEE2050F Course Notes
Division by 2 method:
In this algorithm we start by calculating the Least Significant Bit (b0 ) in the binary numeral (B)
first and then move towards the Most Significant Bit (bn ) repeatedly dividing the decimal number
(di ) by 2 to find the quotient (qi ) and remainder (ri ) for each index (i ). The reminder equals
the binary digit (bi ) and the quotient becomes the seed for the next step (di+1 ). This process
continues until (di = 0) Lets recalculate the binary numeral from the decimal value from Example
1.3 using Algorithm 1.1.
Example 1.4
Convert the decimal number 23510 (D) to binary (B) using the Repeated Division by 2
method.
1. Starting at the LSB (b0 ), where (i = 0), calculate the quotient (q0 ) and remainder (r0 )a
of the decimal number (D = d0 ) divided by 2.
q0 = truncate(d0 ÷ 2)
= truncate(235 ÷ 2)
= truncate(117.5)
= 117
r0 = (d0 ÷ 2) q0 ⇥ 2 q 2 {0, 1}
= (235 ÷ 2) 117 ⇥ 2
= (117.5 117) ⇥ 2
= (0.5) ⇥ 2
=1
b0 = r0
=1
3. And the next decimal seed to the algorithm (d1 ) will be equal to the current quotient
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 7 of 238
EEE2046F/EEE2050F Course Notes
value q0
d1 = q0
= 117
This value will now become the new value of di for the calculation of the next binary
digit in the sequence at i = n + 1.
4. We will now find the binary value of all (m) binary digits from LSB (i = 0) to MSB
(i = m 1 = n), until di = 0 by repeating steps 1 to 3.
23510 = (1 ⇥ 20 ) + (1 ⇥ 21 ) + (0 ⇥ 22 ) + (1 ⇥ 23 ) + (0 ⇥ 24 ) + (1 ⇥ 25 ) + (1 ⇥ 26 ) + (1 ⇥ 27 )
= (1 ⇥ 1) + (1 ⇥ 2) + (0 ⇥ 4) + (1 ⇥ 8) + (0 ⇥ 16) + (1 ⇥ 32) + (1 ⇥ 64) + (1 ⇥ 128)
B =b7 b6 b5 b4 b3 b2 b1 b0
=(11101011)2
6. It is also often useful to write this process out using a table (Table 1.4), where each
column represents one iteration of the process.
Table 1.4: Conversion from decimal to binary using the Repeated Division by
2 method. Start at the LSB (i = 0) and use the Repeated Division by 2 method
(Algorithm 1.2) to find the binary digit (bi ) at this position. Update the value of di+1
to equal the current quotient value qi and move along the table finding each binary
digit until you reach the MSB (i = n). Remember to reverse the order of the digits to
produce the final value.
i 0 1 2 3 4 5 6 7
di 235 117 58 29 14 7 3 1
qi 117 58 29 14 7 3 1 0
ri 1 1 0 1 0 1 1 1
bi 1 1 0 1 0 1 1 1
a
Note: This operation can be replaced by the modulo operator (%) where available.
As computer code written in binary became longer and more complex to read, programmers started
to develop alternative ways to represent this information, which were slightly easier to read and
interpret. The hexadecimal number system was developed in response to these needs. It is a
base-16 positional number system and therefore has 16 symbols. If we want to calculate how
many binary digits we need to represent one hexadecimal digit we can use Equation 1.1.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 8 of 238
EEE2046F/EEE2050F Course Notes
Example 1.5
How many bits of information do you need to represent a single hexadecimal digit?
I = log2 (M)
= log2 (16)
= 4 bits
The hexadecimal symbols look very similar to decimal symbols except that they also use the letters
A, B, C, D, E and F to represent the decimal numbers 1010 to 1510 . The conversion table between
hexadecimal, binary and decimal can be seen in Table 1.7.
A digital designer should be able to convert between hexadecimal and binary values quickly and
without a calculator. It is therefore worth the effort to practice this skill.
Example 1.6
Converting between binary and hexadecimal is not difficult. As we saw in Example 1.5, we
need 4 bits of information to represent a single hexadecimal digit, therefore we start as follows:
1. Split the binary number into groups of 4 bits starting from the right hand side of the
numeral:a
2. Convert each of these 4 bit groups in decimal and then hexadecimal, replacing any
number above 1010 with the appropriate symbol:
(011011110101)2 = 6F516
a
Note: When splitting up the binary number, you may find that you have fewer than four binary digits in
the final set of four. If this is the case add 0’s to the front of this number until you have a set of four and then
begin the conversion step.
Example 1.7
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 9 of 238
EEE2046F/EEE2050F Course Notes
1. Split the hexadecimal number into single digits, starting from the right of the numeral:
(E5A8)16 = (1110010110101000)2
We have now seen how to convert between binary and hexadecimal and visa versa, but how do we
convert between hexadecimal and decimal? Consider the next example.
Example 1.8
3. Multiply each of the decimal numbers by 16 raised to the power of their position in the
sequence:
We have now seen how to convert between binary and hexadecimal and visa versa, but how do
we convert between decimal and hexadecimal? Consider the following two approaches which have
been modified from the Sum of Weights method (see Algorithm 1.3) and the repeated division by
2 method (Algorithm 1.4).
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 10 of 238
EEE2046F/EEE2050F Course Notes
As we can see from Algorithm 1.3, it behaves in a very similar way to Algorithm 1.1, except that
we use Base-16 in our calculations instead of Base-2. In addition we have an added lookup step
that allows us to represent the Hexadecimal symbols {A, B, C, D, E, F}. Lets now look at an
example.
Example 1.9
Convert the decimal number 23510 (D) to hexadecimal (H) using the Sum of Weights method.
To start we need to find out the minimum number of bits needed to represent the decimal
value. We can do this as follows:
1. Calculate the minimum number of numerals (m) needed to represent the decimal num-
ber (D) and find the value of the index of the most significant numeral (hn ) in the
hexadecimal sequence (H), where n = m 1 and H = hn hn 1 . . . h1 h0 .
n = roundup(log16 (D + 1)) 1
= roundup(log16 (235 + 1)) 1
= roundup(log16 (236)) 1
= roundup(1.97) 1
=2 1
=1
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 11 of 238
EEE2046F/EEE2050F Course Notes
Therefore 16n = 161 = 16 is the largest power of sixteen that will divide into 23510 and
produce a quotient that is greater than or equal to 1.
2. Divide 235 by 161 and find the truncated quotient (qi ) (rounded down), this will be the
hexadecimal numeral at position i . If this numeral is greater or equal to 10, lookup the
equivalent hexadecimal symbol and place this in position i ;
hi =truncate(di /16i )
=truncate(235/161 )
=truncate(235/16)
=truncate(14.6875)
=14 or E
1
23510 = Â hi 16i
i=0
=(14 ⇥ 161 ) + (h0 ⇥ 160 )
di 1 = di hi ⇥ 16i
= 235 (14 ⇥ 161 )
= 235 (14 ⇥ 16)
= 235 224
= 11
This value will now become the new value of di for the calculation of the next hexadec-
imal numeral in the sequence at i = n 1.
4. We will now find the hexadecimal values of the remaining numeral. Note if the number
di is less than that current power of 16 (16i ) it will produce a quotient of 0 the current
value of di will be carried to the next step. Now repeat steps 1 to 3 until you have a
value for all the numerals in the sequence.
5. Combine the hexadecimal numerals together, keeping the original order to represent the
hexadecimal number H. Remember to substitute the correct symbol for values greater
or equal to 10:
H =h1 h0
=(EB)16
6. It is also often useful to write this process out using a table (Table 1.5), where each
column represents one iteration of the process.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 12 of 238
EEE2046F/EEE2050F Course Notes
Table 1.5: Conversion from decimal to binary using the Sum of Weights method.
Start at the MSB (i = n) and use the Sum of Weights Algorithm (Algorithm 1.1) to
find the binary digit (bi ) at this position. Update the value of di based on the whether
di 2i and move along the table finding each binary digit until you reach the LSB
(i = 0).
i 1 0
di 235 11
16i 16 1
di ÷ 16i 14.688 11
hi E B
We will now modify the Repeated division by 2 approach for a Base-16 number system. This is
now called the Repeated division by 16 method.
As with the Sum of Weights method this approach has been modified for a Base-16 (hexadecimal)
number system and includes an additional lookup step. These two methods can be modified for
any Base-n positional number system. Lets look at an example.
Example 1.10
Convert the decimal number 23510 (D) to hexadecimal (H) using the Repeated Division by
16 method.
1. Starting at the Least Significant numeral (h0 ), where (i = 0), calculate the quotient
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 13 of 238
EEE2046F/EEE2050F Course Notes
q0 = truncate(d0 ÷ 16)
= truncate(235 ÷ 16)
= truncate(14.688)
= 14
r0 = (d0 ÷ 16) q0 ⇥ 16 q 2 {0, 1, . . . , 14, 15}
= (235 ÷ 16) 14 ⇥ 16
= (14.688 14) ⇥ 16
= (0.688) ⇥ 16
= 11
h0 = r0
= 11
3. And the next decimal seed to the algorithm (d1 ) will be equal to the current quotient
value q0
d1 = q0
= 14
This value will now become the new value of di for the calculation of the next hexadec-
imal numeral in the sequence at i = n + 1.
4. We will now find the hexadecimal value of all (n + 1) numerals from Least Significant
(i = 0) to Most Significant (i = n), until di = 0 by repeating steps 1 to 3.
5. Combine the hexadecimal numerals together, reversing the order and looking up the
symbols for any numerals greater than or equal to 10:
H =h1 h0
=(EB)16 where E16 = 1410 and B16 = 1110
6. It is also often useful to write this process out using a table (Table 1.6), where each
column represents one iteration of the process.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 14 of 238
EEE2046F/EEE2050F Course Notes
Table 1.6: Conversion from decimal to hexadecimal using the Repeated Division
by 16 method. Start at the Least Significant numeral (i = 0) and use the Repeated
Division by 16 method (Algorithm 1.4) to find the hexadecimal numeral (hi ) at this
position. Update the value of di+1 to equal the current quotient value qi and move
along the table finding each hexadecimal numeral until you reach the Most Significant
numeral (i = n). Remember to reverse the order of the numerals to produce the final
value.
i 0 1
di 235 14
qi 14 0
ri 11 14
bi B E
a
Note: This operation can be replaced by the modulo operator (%) where available.
A conversion table (Table 1.7) is provided for reference for conversion between hexadecimal, 4-
bit binary and decimal. It is extremely worthwhile to learn this table (and understand how it is
produced if you forget a number) as it makes number conversion much easier.
Up to this point we have only worked with unsigned binary numbers, in other words only positive
numbers including zero. We may need to represent both positive and negative numbers in binary
and therefore need an alternative way to interpret a binary numeral or string. These are called
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 15 of 238
EEE2046F/EEE2050F Course Notes
In this representation, the most significant bit in the binary numeral represents the sign of the
number. The remaining binary digits represent the magnitude or value of the numeral. This means
that if we have an 8-bit binary numeral, the MSB will be the sign and the other 7-bits will be the
magnitude. A positive sign bit in this system is 0 and a negative sign bit is 1. The range of values
that can be represented using (m) bits in this number system is [ 2n + 1, 2n 1].
Table 1.8: Signed 8-bit binary number (Sign-Magnitude). The most significant
bit (MSB) in a binary digit represents the sign, while the remaining bits represent the
magnitude of the numeral.
7 6 5 4 3 2 1 0
Sign Magnitude
Example 1.11
Represent the decimal number +910 using 8-bits in binary using the sign/magnitude binary
number system.
1. Convert the decimal number without the sign to binary using 8 1 = 7 bits:
910 = 0001001
2. Now add the positive sign bit (0) in the MSB position in the numeral to make the 8-bit
number:
+910 = 000010012
Note that we would need at least 5-bits to represent this number as opposed to the 4-bits to
represent an unsigned binary number.
Example 1.12
Represent the decimal number 910 using 8-bits in binary using the sign/magnitude binary
number system.
3
Note that a signed and unsigned binary string look the same, i.e. a series of 0’s and 1’s. We therefore need to
know what representation we are using before we interpret the numeral.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 16 of 238
EEE2046F/EEE2050F Course Notes
1. Convert the decimal number without the sign to binary using 8 1 = 7 bits:
910 = 0001001
2. Now add the negative sign bit (1) in the MSB position in the numeral to make the 8-bit
number:
910 = 100010012
Although this system is easy to understand, there are problems with it. Standard binary addition
does not work with this representation and there is a positive and negative zero which can cause
confusion. Therefore this representation is no longer used in digital system design, although it was
used in the past.
The one’s complement signed binary number system uses an alternative approach to representing
positive and negative numbers. In this system, a negative value is obtained by inverting all the
bits of the equivalent unsigned or positive binary number. It suffers from a similar problem to the
sign/magnitude representation as it also has both a positive and negative zero value. The range of
values that can be represented using (m = n + 1) bits in this number system is [ 2n + 1, 2n 1].
Let’s consider an example.
Example 1.13
Represent the decimal number 910 in binary using the one’s complement binary number
system using 8-bits.
1. Convert the decimal number without the sign to binary using the correct number of bits
required for the representation:
910 = 00001001
910 = 111101102
As we can see in this example, the MSB is a 1 which indicates that the result is a negative value
4 . Although this system is very simple to implement electronically, it does still produce two zeros
which makes binary arithmetic more complex. We will now consider one more system, to represent
sign numbers in binary, which is simple to implement electronically, makes binary arithmetic circuits
easy to produce and only produces a single zero.
4
Note: Consider what happens if we just used 4-bits to represent the result. We would then have an overflow
condition.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 17 of 238
EEE2046F/EEE2050F Course Notes
The two’s complement signed binary number system was designed to deal with the problems that
are encountered with the previous two representations. There is a single value for zero and we are
able to add any two’s complement number using standard binary addition. The range of values
that can be represented using (m) bits in this number system is [ 2n , 2n 1], where n = m 1.
The algorithm to convert a binary number to its equivalent 2’s complement value is as follows 5 :
Example 1.14
Convert the decimal number 910 using 8-bit binary using the 2’s complement binary number
system.
1. Convert the decimal number without the sign to binary using 8-bits:
910 = 00001001
= 11110110
1 1 1 1 0 1 1 0
+ 0 0 0 0 0 0 0 1
1 1 1 1 0 1 1 1
Although it may not be immediately clear why this works, consider the example below:
Example 1.15
Convert the decimal number 0 to 1’s complement and then into 2’s complement using 4-bits.
5
Note: There is a alternative approach to convert a decimal number into 2’s complement number using the
following algorithm: First convert the unsigned decimal number to binary, then starting from the LSB move left
through the digits until you encounter the first 1. Leave this 1 as it is. Then move onto the next digits, inverting
them one by one until you have reached the end of the number. The result is now the 2’s complement.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 18 of 238
EEE2046F/EEE2050F Course Notes
1. Convert the decimal number without the sign to binary using 4-bits:
010 = 0000
= 1111
We note at this point that we have converted the number into its 1’s complement form
and that we have two possible values for zero (+0 = 00002 and 0 = 11112 ). Now let’s
consider what happens when we add 1 to the -0 result.
1 1 1 1
+ 0 0 0 1
1 0 0 0 0
We see here that we actually remove the -0 from the number system by adding 1, if we
keep the result in a 4-bit container i.e. drop the carry bit. This reduces confusion and
potential circuit complexity by only producing a single 0.
We will see in Section 1.3.5 how 2’s complement makes binary subtraction and addition easy. Lets
consider all the signed numbers we can represent with 4-bits using sign/magnitude, 1’s complement
and 2’s complement:
Table 1.9: 4-bit Signed Binary Numbers. The conversion between decimal,
sign/magnitude, 1’s complement and 2’s complement 4-bit binary.
From this table we can see a few things. Firstly we need at least 4-bits to represent these
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 19 of 238
EEE2046F/EEE2050F Course Notes
numbers.6 We can also see that the most significant bit seems to act like a sign bit where 0
represents a positive number and 1 represents a negative number, however this number system
allows for easy addition and subtraction of numbers unlike the sign/magnitude representation and
is used to represent all signed values in computer systems.
In this section we will consider basic arithmetic which can be performed on binary numbers. These
algorithms form the basis of the physical hardware that is used inside the ’brain’ of a digital
processor and therefore are very important to understand. We will look at addition, subtraction
and multiplication.
Binary addition
Binary addition works in a very similar way to decimal addition as both are positional number
systems. We first need to consider the rules for adding two 1-bit unsigned binary numbers together.
Example 1.16
Add the following two unsigned 1-bit binary numbers together: A and B for the various cases
below:
1. A = 02 and B = 02
0 A (010 )
+ 0 B (010 )
0 Sum (010 )
2. A = 02 and B = 12
0 A (010 )
+ 1 B (110 )
1 Sum (110 )
3. A = 12 and B = 02
1 A (110 )
+ 0 B (010 )
1 Sum (110 )
4. A = 12 and B = 12
6
This makes sense if we consider Equation 1.1 as we need to represent 16 values in total.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 20 of 238
EEE2046F/EEE2050F Course Notes
1 A (110 )
+ 1 B (110 )
1 0 Sum (210 )
We can see that when we add the 1-bit binary digits 1 and 1 together we now need
2-bits to represent the result. This results in a carry-out condition, in other words the
result is too large to be represented by the available bits and is ’carried’ out of the
available sized binary numeral container. As we will see later in this book, this can be a
problem if we can not increase the number of bits used to represent the number.
We will now illustrate binary addition of larger numbers with this example:
Example 1.17
Add these two unsigned binary numbers together: A = 11012 and B = 10112
We start by writing out both numbers with each of the binary digits of the same magnitude
lined up. We then add the numbers bit by bit starting from the LSB and moving to the MSB.
1 1 0 1 A (1310 )
+ 1 0 1 1 B (1110 )
Sum
1 Carry
1 1 0 1 A (1310 )
+ 1 0 1 1 B (1110 )
0 Sum
1 1 Carry
1 1 0 1 A (1310 )
+ 1 0 1 1 B (1110 )
0 0 Sum
1 1 1 Carry
1 1 0 1 A (1310 )
+ 1 0 1 1 B (1110 )
0 0 0 Sum
1 1 1 1 Carry
1 1 0 1 A (1310 )
+ 1 0 1 1 B (1110 )
1 1 0 0 0 Sum (2410 )
We will now consider the addition of signed numbers using the two’s complement representation.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 21 of 238
EEE2046F/EEE2050F Course Notes
Example 1.18
Add these two numbers together using 2’s complement representation: 510 and 210
We first need to find the 2’s complement of each of the numbers and then we can add them
together using normal binary addition.
0 1 0 1
+ 1 1 1 0
1 0 0 1 1
3. Drop any overflow bits if they are present to obtain the final result:
The fifth bit is dropped and we are left with 00112 or 310 which we can see is the
correct answer.
1.3.6 Subtraction
Binary subtraction is another fundamental arithmetic operation and works in a similar fashion to
decimal subtraction. Consider the following example which shows the all the 1-bit cases. Consider
these examples:
Example 1.19
Subtract the following two unsigned 1-bit binary numbers from each another: A - B for the
various cases below:
1. A = 02 and B = 02
0 A (010 )
- 0 B (010 )
0 Sum (010 )
2. A = 02 and B = 12
0 A (010 )
+ 1 B (110 )
1 Sum (110 )
3. A = 12 and B = 02
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 22 of 238
EEE2046F/EEE2050F Course Notes
1 A (110 )
- 0 B (010 )
1 Sum (110 )
4. A = 12 and B = 12
1 A (110 )
- 1 B (110 )
0 0 Sum (010 )
We can see that when we add the 1-bit binary digits 1 and 1 together we now need
2-bits to represent the result. This results in a carry-out condition, in other words the
result is too large to be represented by the available bits and is ’carried’ out of the
available sized binary numeral container. As we will see later in this book, this can be a
problem if we can not increase the number of bits used to represent the number.
Example 1.20
Subtract these two unsigned binary numbers from one another: 11012 and 10112
1 1 0 1 A (1310 )
- 1 0 1 1 B (1110 )
Difference
1 1 0 1 A (1310 )
- 1 0 1 1 B (1110 )
0 Difference
10
1 1 0
◆ 1 A (1310 )
- 1 01
◆ 1 1 B (1110 )
1 0 Difference
10
1 1 0
◆ 1 A (1310 )
- 1 01
◆ 1 1 B (1110 )
0 1 0 Difference
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 23 of 238
EEE2046F/EEE2050F Course Notes
10
1 1 0
◆ 1 A (1310 )
- 1 0
◆1 1 1 B (1110 )
0 0 1 0 Difference (210 )
This process binary subtraction is simply taking the two’s complement of the number to be sub-
tracted and adding it to the first number.
Adding two same signed 2’s complement numbers (either both positive or both negative) together
may result in an overflow and an incorrect result if their sum is greater than (2n 1 1) or less
than ( 2n 1 ). This will cause the answer to have an incorrect sign which is unlike the overflow
condition for unsigned numbers. See example:
Example 1.21
Add these two numbers together using 2’s complement representation: 510 and 410
We first need to find the 2’s complement of each of the numbers and then we can add them
together using normal binary addition.
1 0 1 1
+ 1 1 0 0
1 0 1 1 1
3. We can see here that we are left with 01112 or 710 which we can see is the incorrect
answer. However if we use 5-bits to represent the number 101112 we see that we now
have the correct answer which is -910 .
Binary multiplication
Finally we will consider binary multiplication. This process is also quite simple as seen in the
example:
Example 1.22
Multiply these two numbers unsigned binary numbers together: 10112 and 1012
This process works like normal decimal multiplication with the following rules:
• 0⇥0 = 0
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 24 of 238
EEE2046F/EEE2050F Course Notes
• 0⇥1 = 0
• 1⇥0 = 0
• 1⇥1 = 1
1 0 1 1
⇥ 1 0 1
1 0 1 1
0 0 0 0
+ 1 0 1 1
1 1 0 1 1 1
We can see how multiplication has increased the number of bits needed to represent the
product. This means that we need to be careful of overflows out of this operation.
We have now considered the most common number representations used in modern digital systems.
1.4 Summary
In this chapter we have covered the basic concepts used in a digital system. After reading this
chapter you should now be familiar with the following concepts:
1. Digital information
In the next chapter we will look at the basic electronic hardware that is used to manipulate these
values.
R.A. Verrinder (Revision date: Monday 18th April, 2022) Page 25 of 238
Bibliography
[1] George Boole. An investigation of the laws of thought: on which are founded the mathemat-
ical theories of logic and probabilities, volume 2. Walton and Maberly, 1854.
[2] Randal E. Bryant and David R. O’Hallaron. Computer systems: A programmers perspective.
Prentice Hall, second edition edition, 2011.
[3] cplusplus.com. sprintf, 2015.
[4] James Gowans. Introduction to microcontrollers. Eee2039w-d course notes, University of
Cape Town, Cape Town, 2014.
[5] David Money Harris and Sarah L. Harris. Digital design and computer architecture. Morgan
Kaufmann, San Francisco, California, 1st ed. edition, 2007.
[6] Microchip Technology Inc. TC74: Tiny serial digital thermal sensor. Datasheet DS21462C,
2002.
[7] Texas Instruments. MAX232x Dual EIA-232 Drivers/Receivers. Datasheet SLLS047M Ð
February 1989 Ð Revised November 2014, 2014.
[8] Brian W. Kernighan and Dennis M. Richie. The C programming language. Prentice Hall
Software Series, second edition edition, 1988.
[9] M. Morris Mano and Charles R. Kime. Logic and computer design fundamentals. Prentice-Hall
Inc., Upper Saddle River, New Jersey, 2nd ed. edition, 2001.
[10] MCD Application Team. stm32f0xx.h.
[11] LLC ON Semiconductor Components Industries. CAT25010, CAT25020, CAT25040, 1-Kb,
2-Kb and 4-Kb SPI Serial CMOS EEPROM. Datasheet Rev. 24, CAT25010/D, 2013.
[12] Claude E. Shannon. A mathematical theory of communication. Bell System Technical Journal,
27(3):379–423, July 1948.
[13] STMicroelectronics. ST-LINK/V2 in-circuit debugger/programmer for STM8 and STM32.
Data Brief ST-LINK/V2, Doc ID 018751 Rev. 3, 2012.
[14] STMicroelectronics. STM32F051xx datasheet. Datasheet DocID022265 Rev. 4, 2014.
[15] STMicroelectronics. STM32F0x1/STM32F0x2/STM32F0x8 advanced ARM-based 32-bit
MCUs reference manual. Reference Manual RM0091, DocID018940 Rev. 5, 2014.
[16] Tutorialspoint. C - switch statement: C programming tutorial, 2015.
[17] Ltd. Xiamen Amotec Display Co. Specification of LDC module. Module No: ADM1602K-
NSA-FBS/3.3V. Datasheet Rev. 00, 2008.
238