Computer Arithmetic and Logic
Computer Arithmetic and Logic
Contents
Introduction
Aim
Objective
Topics
Decimal Numbering System (Base 10)
Binary Numbering System (Base 2)
Binary-to-Decimal Conversion
Decimal-to-Binary Conversion
Hexadecimal Numbering System (Base 16)
Hexadecimal Conversions
Summary
Problems
References
1.1 Introduction
Computer systems operate using digital electronic circuits. Digital
circuitry uses binary input and output states which are represented
by 0 and 1. As humans we are accustomed to using a decimal
number system to perform arithmetic and other transactions. On the
other hand the computer uses the binary number system to perform
its functions. Therefore, it is important that for the human and the
computer to interface, there has to be a conversion between the two
systems. The hexadecimal number system is often used in computer
science because of its shorter code compared to the difficult to read
binary system. It is important for a computer programmer to be
familiar with this numbering system. In this unit decimal, binary and
hexadecimal number systems are introduced. In addition you will
learn techniques of how to convert between them.
1.2 Aim
This Unit aims to introduce you to the number systems used in
computer systems and how to convert between them.
6
1.3 Objectives
At the completion of this unit you should be able to
7
1.4 Topics
The decimal system is referred to as base, or radix, of 10. This means that each
digit in the number is multiplied by 10 raised to a power corresponding to that
digit’s position. Therefore the number 523 is
Figure 1
A number with both an integer and fractional part has digits raised to both
positive and negative powers of 10. Hence 523.24 is
8
1.4.2 Binary Numbering System (Base 2)
In the binary number system the digits 0 and 1, are used for each position of a
number. Each position is weighted to a power of 2 depending on its position. For
the number 101 means
Example
A binary number with both an integer and fractional part has digits raised to both
9
positive and negative powers of 2. Hence 101.110 is
Exercise
10
1.4.2.1 Successive subtraction method.
11
Example
The first remainder, 0, is the least significant bit (LSB) of the answer; the last
remainder, 1, is the most significant bit (MSB) of the answer. Therefore, the
answer is as follows:
12210 = 1111010
Exercise: Convert the decimal number 1243 10 to binary. Verify the answer by
converting back to decimal.
12
Figure 3
For you to convert a binary number to hexadecimal number, group the binary
number in groups of 4 (starting from the least significant bit) and write down the
equivalent hex digit.
Solution:
Step 1: Group the binary number in groups of 4
starting from the least significant. Left over digits are
padded with zeros. Hence
13
Exercise: Convert the following binary numbers to hexadecimal:
a. 1001110101111000
b. 1
01011100010
Solution:
3 F A 6
0011 1111 1010 0110
3FA616 = 0011111110100110 2
Solution:
3 F A 6
3 15 10 6
3FA616 = 16294
14
To convert decimal numbers to hexadecimal use the repeated division
method as in the example below.
Solution:
1018 ÷ 16 = 63 remainder 10 = A
63 ÷ 16 = 3 remainder 15 = F
3 ÷ 16 = 0 remainder 3 = 3
1629410 = 3FA616
1.5 Summary
In this unit you have been introduced to the decimal, binary and
hexadecimal number systems that are used in digital computers. You
should be able to describe how they are represented. In addition you have
been shown the various techniques on how to convert between them. It is
important that you practice how to perform these techniques so that you
can quickly apply them as a programmer.
1.6 Problems
1.7 References
http://code.tutsplus.com/articles/number-systems-an-introduction-to-
binary-hexadecimal-and-more--active-10848
http://www.byte-notes.com/number-system-computer
16