Nothing Special   »   [go: up one dir, main page]

0% found this document useful (0 votes)
21 views15 pages

Wa0000.

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 15

TSHWANE UNIVERSITY OF TECHNOLOGY

FACULTY INFORMATION AND COMMUNICATION TECHNOLOGY

2024
NUMBER SYSTEMS
COURSE NAME: NATIONAL DIPLOMA:
FOUNDATION IT INFORMATION TECHNOLOGY
B TECH FINANCIAL INFORMATION SYSTEMS

SUBJECT NAME: COMPUTING FUNDAMENTALS A


SUBJECT CODE: CFAF05D

REVISED by: MANTULI


© Copyright Reserved

All rights reserved. Apart from any fair dealing for the purpose of research criticism or review as permitted under
Copyright Act, no part of this document may be reproduced or transmitted in any other form or by any means, electronic
or mechanical, including photocopy and recording, without permission in writing from the publisher.

Acknowledgements Thank you to STUDY OPPORTUNITIES for allowing us to use


their publications to compile these notes.

CFAF05D #.1
Chapter 1 Data Representation
Objectives: When you have completed this chapter, you should be able to:
understand and convert the decimal, binary, hexadecimal number systems.

1. Introduction
A computer is based on the most basic beginnings of 2 electronic states. The electronic circuits
of a computer can only be in one of two states: ‘on’ or ‘off’. A bit (binary digit) represents these
two states. There are therefore two values which a bit or binary digit can be, namely 0 and 1.
One could say that strings of ones and zeros are the mother tongue of the computer!

2. Grouping of bits
Computer manufacturers use a grouping of bits to represent letters, figures and special
characters such as? or +. A group of eight bits is called a byte.

A computer word is the number of bits that can be handled as a unit. The word length of
computers differs. In modern computers it is normally 32 or 64 bits.

3. Number systems
There are different number systems. The number system that is familiar to us is called the
decimal number system.

The decimal number system uses ten symbols (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) to represent
numbers. The decimal number system therefore has a base of 10.

The following table shows the properties of different number systems.


Number Base Number of Symbols used to represent Example of the
system symbols numbers number 12
Decimal 10 10 0123456789 12
Binary 2 2 01 1100
Octal 8 8 01234567 14
Hexadecimal 16 16 0123456789ABCDEF C

3.1 Place value


Consider the decimal number 612. The value of the 6 in 612 is 600. For the value 68, 6’s place
value is 60.

The place of the figure determines its value. This concept is the same for all number systems.
The place values of the decimal number system are shown in the following table.

Power 103 102 101 100 10-1 10-2 10-3


Place value 1000 100 10 1 0,1 0,01 0,001
Example of number 5 3 4 7 , 2 3 1

CFAF05D #.2
3.2 Expanded notation
By multiplying numbers with their place values, you can write numbers in expanded notation.
Examples:
5347,23110 = 5x103 + 3x102 + 4x101 + 7x100 + 2x10-1 + 3x10-2 + 1x10-3
702,0710 = 7x102 + 0x101 + 2x100 + 0x10-1 + 7x10-2

Take note: Since we are working with different number systems you must include the base to
ensure that everybody knows in which number system you are working. If you do not include
the base, marks will be deducted in this module.

4. Binary number system


We have already seen that the binary number system consists of the numbers 0 and 1. The
place values of the binary number system are shown in the following table.
Power 23 22 21 20 2-1 2-2 2-3
Place value 8 4 2 1 0,5 0,25 0,125
Example of number 1 1 0 1 , 1 0 1

4.1 Expanded notation


Example:
1101,1012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3

Take note: The methods used in this module and these notes, will be the only methods
that will be marked. Indicate all steps to get full marks!

4.2 Converting from binary to decimal


If a binary number is written in expanded notation, it is easy to calculate the decimal number.
Do the following to obtain the decimal value of a binary number.

• Write the number in expanded notation


• Multiply each number with its place value
• Add these values together to obtain the decimal value.

Example 1: Convert 10112 to a decimal number.


10112 = 1x23 + 0x22 + 1x21 + 1x2 0 Write the number in expanded notation.
= 1x8 + 0x4 + 1x2 + 1x1 Multiply each number with its place value.
=8+0+2+1 Add these values together to obtain the
= 1110 decimal value.

Example 2: Convert 11011012 to a decimal number.


11011012 = 1x26 + 1x25 + 0x24 +1x23 + 1x22 + 0x21 + 1x20
= 1x64 + 1x32 + 0x16 + 1x8 + 1x4 + 0x2 + 1x1
= 64 + 32 + 0 + 8 + 4 + 0 + 1
= 10910

CFAF05D #.3
Example 3: Convert 100111,012 to a decimal number.
The conversions can also be done by writing the place values above each binary number and
then adding the place values, which are not zero together.
You must add decimal numbers, else your answer will be wrong!

100111,012 = 1x25 + 0x24 +0x23 + 1x22 + 1x21 + 1x20 + 1x2-1 + 1x2-2


= 1x32 + 0x16 + 0x8 + 1x4 + 1x2 + 1x1 + 1x0,5 + 1x0,25
= 32 + 0 + 0 + 4 + 2 + 1+ 0,5 + 0,25
= 39,7510

Example 4: Convert 101,1012 to a decimal number.


101,1012 = 1x22 + 0x21 + 1x20 + 1x2-1 + 0x2-2 + 1x2-2
= 1x4 + 0x2 + 1x1 + 1x0,5 + 0x0,25 + 0x0,125
= 4 + 0 + 1+ 0,5 + 0 + 0,125
= 5,62510

You can test your answer by using the place value. Therefore, for Example 4 you can test
your answer as follows:

Step 1: Write down the place values of the binary number system. It is only necessary to
write down the place values smaller or equal to 510 and bigger or equal to 0,62510

Place values 4 2 1 0,5 0,25 0,125

Step 2: Start at the left-hand side of the decimal comma, and determine from left to right
what combination of place values make up the number 510

Place values 4 2 1
Number 1 0 1

1 + 4 = 510

Step 3: Start at the decimal comma and determine from right to left what combination of
place values make up the fraction 0,62510

Place values 4 2 1 0,5 0,25 0,125


Number 1 0 1 , 1 0 1

4 + 1+ 0,5 + 0,125 = 5,62510

Therefore 5,62510 = 101,1012

CFAF05D #.4
Exercise
1. Convert the following binary numbers to decimal numbers.

a) 10102 b) 111112 c) 1010012


d) 110011002 e) 100000112 f) 111011112
g) 101,1012 h) 1100,0112 i) 10111,1012

4.3 Converting from decimal to binary


The integer and fractional parts of each number are done separately.

4.3.1 The integer part


With integer conversion, division by two takes place successively until the quotient becomes 0. In
each step the remainder (0 or 1) will be the binary digit in that column. The binary integer is
written from bottom to top.

Example 1: Convert 9010 to a binary number.


Step 1: Divide by 2 until the answer is 0. Write the remainder of each division on the right-
hand side

2 90
2 45 r 0
2 22 r 1
2 11 r 0
2 5 r 1
2 2 r 1
2 1 r 0
0 r 1

Step 2: Write the remainders down from bottom to top.

Therefore 9010 = 10110102

Example 2: Convert 13710 to a binary number.

2 137
2 68 r 1
2 34 r 0
2 17 r 0
2 8 r 1
2 4 r 0
2 2 r 0
2 1 r 0
0 r 1

Therefore 13710 = 100010012

CFAF05D #.5
Exercise
1. Convert the following decimal numbers to binary numbers.

a) 2710 b) 8510 c) 11210 d) 12510 e) 10010

2. Hexadecimal number system

The base of the hexadecimal number system is 16. Therefore the hexadecimal number system
consists of 16 different elements. The first 10 elements in the hexadecimal number system
are 0 to 9.

Because the elements of a number system must all be single symbols, the hexadecimal number
system uses the letters A, B, C, D, E and F as elements to represent the values 10 to 15. This
is shown in the table:
Decimal Hexadecimal
10 A
11 B
12 C
13 D
14 E
15 F

The table of place values of the hexadecimal number system is as follows:

Power 162 161 160


Place value 256 16 1
Example of number 1 A 7

2.1 Converting from hexadecimal to decimal


If a hexadecimal number is written in expanded notation, it is easy to calculate the
decimal value. The same method used for conversion of binary to decimal is followed:

• Write the number in expanded notation.


• Multiply each number with its place value.
• Add these numbers together to obtain the decimal value.

Example: Convert AF316 to a decimal number.


AF316 = A x 162 + F x 161 + 3 x 160 Write the number in expanded notation.
= A x 256 + F x 16 + 3 x 1 Multiply each number with its place value.
= 10 x 256 + 15 x 16 + 3 x 1
= 2560 + 240 + 3 Add these numbers together to obtain the
= 280310 decimal value.

CFAF05D #.10
You can test your answer by using the place value.

Place values 256 16 1


Number A F 3

2560+ 240 + 3 = 280310

3. Converting from decimal to hexadecimal

Example 1: Convert 28510 to a hexadecimal number.


Step 1: Divide by 16 until the answer is 0. Write the remainder of each division on the
right- hand side.
16 285
16 17 rD
16 1 r1
0 r1

The remainder was 13, but 13 is represented by a D in hexadecimal and


therefore you must write the D and not the 13.

Step 2: Write the remainders down from bottom to top.

Therefore 28510 =

11D16 You can test your answer by using the place value.

Place values 256 16 1


Number 1 1 D

256 + 16 + 13 = 28510

Exercise
1. Convert the following hexadecimal numbers to decimal.
a) 2416 b) A216 c) 11016
d) B0316 e) AB1216 f) 1BCD16

2. Convert the following decimal numbers to hexadecimal.


a) 2010 b) 3710 c) 120
10
d) 29010 e) 145610 f) 1200
10

4. Converting from binary to hexadecimal

Hexadecimal values are a shorter notation of the binary equivalent. The contents of files of
data are sometimes given in hexadecimal code. The conversion between the binary number

CFAF05D #.10
system and the decimal number system is very easy. Sometimes the hexadecimal code is
used for a
shorter notation than binary code.

Following the relationship between the place values of binary numbers and the hexadecimal
numbers, the conversion between this number system is very simple and quick. Each group
of four bits is replaced with a hexadecimal number.

Example 1: Convert 101110012 to a hexadecimal number.


Step 1: Start at the binary comma and divide the binary number into groups of four. (You
can add extra zeros in front to form groups of four – see next example).

1011 1001

Step 2: Replace each group with a hexadecimal number.

1011 1001
B 9

1011 10012 = B916

Example 2: Convert 11011111012 to a hexadecimal number.

0011 0111 1101


3 7 D

11 0111 11012 = 37D16

5. Converting from hexadecimal to binary

Example 1: Convert A316 to a binary number.


To convert a hexadecimal number to a binary number, each hexadecimal number must be
written as a binary number of four bits.

A 3
1010 0011

A316 = 1010 00112

CFAF05D #.10
Example 2: Convert 2C716 to a binary number.

2 C 7
0010 1100 0111
Zero’s in front of a number has no meaning;
therefore you do not need to write it down. It
2C716 = 10 1100 01112
is not wrong to leave it, i.e. 0010 1100 01112

CFAF05D #.10
Exercise
1. Convert the following binary numbers to hexadecimal.

a) 100111002 b) 1011012 c) 1112


d) 10111111112 e) 1000000100002 f) 1010011002

2. Convert the following hexadecimal numbers to binary.


a) A716 b) D1516 c) 100016
d) AAB16 e) 34E16 f) 5E816

3. Complete the letters a - j of the following table.


Base 2 Base 10 Base 16
a b 75 AF
c e h df
101111 125 12A
g j
i

4. Write the number 13 as a


a) hexadecimal number
b) binary number

5. Determine the value of X in each of the following cases.


a) X2 = 1610 b) X10 = 21016 c) 10012 = X10
d) 10016 = X2 e) A3516 = X10 f) 23110 = X16
g) 12110 = X2 h) 101111102 = X16 i) X8 = 11210

6. Give the answer for each of the following:


a) The decimal value of 10016.
b) The hexadecimal value of 17810.
c) The binary value of 10110.
d) The hexadecimal value of 10010002.
e) The decimal value of 1100112.
f) The binary value of BC216.

CFAF05D 11
Chapter 2 Binary addition

When you have completed this chapter, you should be able to


add binary numbers;
write integers in sign-and-size code;
convert integer numbers to two’s complement and visa versa.
do two’s complement arithmetic

1. Introduction
All data is represented in a computer in one of two conditions, zeros and one’s. To be able to
understand better how a computer works, it is useful to know how numbers are represented in a
computer.

Fewer mistakes are made when the correct data types are used in Turbo Pascal. When
programming in Pascal, it is important to know how the different types of data such as REAL,
INTEGER and LONGINT are represented in the computer.

In other programs such as a database, it is important to know that we get different data types, for
example, integers and real and that the internal representation differs.

2. Addition of binary numbers


The addition of binary numbers works according to the same principles as those of the decimal
number system. Let us see what happens when two decimal numbers are added:

Transfer 111
768
+475
1243

It is always done from right to left.

The following combinations exist when two single digit binary numbers are added:

0 0 1 1
+0 +1 +0 +1
0 1 1 1 0 (transfer of 1)

Example 1: Calculate the following: 101012 + 102


Transfer (none)
10101
+ 10
1 0 1 1 12

CFAF05D 12
Example 2: Calculate the following: 101112 + 1102
Transfer 11
10111
+ 110
1 1 1 012

Remember: 12 + 12 + 12 = 112

Example 3: Calculate the following: 111012 + 1112 + 10112


Transfer 1 1 1 1

11101
When three or more numbers must be
+1 1 1
added, the chances of making a mistake becomes
100100
much smaller if the first two numbers are added and
+1 0 1 1
then the third one
1 0 1 1 1 12

To check whether the addition was correctly done, the numbers may be changed to decimals.

111012 = 1x24 +1x23 + 1x22 + 0x21 + 1x20


= 1x16 + 1x8 + 1x4 + 0x2 + 1x1
= 16 + 8 + 4 + 0 + 1
= 2910

1112 = 1x22 + 1x21 + 1x20


= 1x4 + 1x2 + 1x1
=4+2+1
= 710

You can do the same with the other numbers:

111012 + 1112 + 10112 = 1011112


2910 + 710 + 1110 = 4710

The addition was therefore correctly done.

Exercise
1. Calculate the following:

a) 10012 + 1102 b) 11102 + 1012


c) 1011112 + 11112 d) 11112 + 1112
e) 10112 + 11112 + 1012 f) 1100002 + 10112 + 11112

CFAF05D 13
3. Internal representation of integers
Digital systems like computers must be able to represent positive and negative numbers. There
are three methods of representing positive and negative integers namely the
• sign-and-size code
• one’s complement
• two’s complement

3.1 The sign-and-size code


This code uses the ordinary binary equivalent of a number and places an extra bit in the front in
order to represent the sign. In the case of a positive number, the extra bit will be a 0, and in the
case of a negative number, the extra bit will be a 1.

Example 1: Use 1 byte to represent the numbers, -12 and 12, in the sign-and-size-code.

2 12
2 6 r0
2 3 r0
2 1 r1
0 r1
Therefore 1210 = 11002

Take note: One byte (7 bits + sign bit = 8 bits) is used throughout for the
representations.

One byte (7 bits + the sign bit = 8 bits) is used throughout for the representations.
Sign-and-size-code:

12 0 0 0 0 1 1 0 0

-12 1 0 0 0 1 1 0 0

Example 2: Convert the number -120 to the sign-and-size-code and represent it in 1 byte.
2 120
2 60 r0
2 30 r0
2 15 r0
2 7 r1
2 3 r1
2 1 r1
0 r1
Therefore 12010 = 11110002
Sign-and-size-code:
For readability and to
-12010 1 1 1 1 1 0 0 0 use a standard format
throughout, you must
We will write it as: -12010 = 1 1111 0002 write the sign bit, leave a
space followed by four
digits, a space, and the
remaining three digits. #.14
The sign-and-size method is not generally used in computers. This type of representation results
in problems when adding is done, as the sign bit must be handled separately from the rest of the
number.

Example 3: Add -12 to 12. (We have used the conversion in Example 1 to just add the two
numbers)

1 0001 100
+0 0001 100
1 0 0 1 1 0 0 02

Convert the answer to a decimal number:

110002 = 1x24 + 1x23 + 0x22 + 0x21 + 0x20


= 1x16 + 1x8 + 0x4 + 0x2 + 0x1
= 16 + 8 + 0 + 0 + 0
= 2410

Therefore 1 0011 0002 = -2410

The answer is -2410, which is wrong. We know the answer is 0. The two’s complement
representation solves this problem.
Exercise

1. Represent the following decimal numbers in the sign-and-size code. Use 1 byte for the
representation.
a) 6710 b) -3510 c) 9710
d) -12410 e) -12710 f) -11110

2. The following binary numbers are written in sign-and-size code. Write down the decimal
equivalent.
a) 0 0001 1012 b) 1 0111 0002 c) 0 0011 1012
d) 1 1101 1112 e) 1 0101 0102 f) 1 1111 1012

3.2 Two’s complement representation


Two’s complement is used in computers to do manipulations with positive and negative
numbers. Two’s complement is the most generally used representation of integers. Programmers
of computers writing in low-level languages like Assembler, use two’s complement to represent
numbers.

3.2.1 Conversion of positive decimal numbers to two’s complement


The two’s complement representation of a positive number is the binary value of the number
with a 0 in front to indicate that it is a positive number. Two’s complement representation of a
positive number is thus the same as that in sign-and-size code.

CFAF05D #.15
Take note: You should know now how to convert numbers. We will only give the answers
in the examples that follow.

Example 1: Give the two’s complement representation of the number 15 10.


1510 = 0 0001 1112

Example 2: Give the two’s complement representation of the number 8710.


8710 = 0 1010 1112

Example 3: Give the two’s complement representation of the number 12310.


12310 = 0 1111 0112

CFAF05D #.16

You might also like