0% found this document useful (0 votes)
92 views55 pages

Data Representation Book 1

This document discusses data representation in computers. It begins by explaining that computers process data digitally using the binary digits 0 and 1. The rest of the document covers: 1) Converting between different number bases like binary, decimal, and octal. This involves dividing numbers and listing remainders. 2) Representing fractional numbers in binary using place values. 3) Distinguishing between finite and infinite binary fractions. 4) Examples are provided to demonstrate converting specific numbers between bases.

Uploaded by

shammahzuze05
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)
92 views55 pages

Data Representation Book 1

This document discusses data representation in computers. It begins by explaining that computers process data digitally using the binary digits 0 and 1. The rest of the document covers: 1) Converting between different number bases like binary, decimal, and octal. This involves dividing numbers and listing remainders. 2) Representing fractional numbers in binary using place values. 3) Distinguishing between finite and infinite binary fractions. 4) Examples are provided to demonstrate converting specific numbers between bases.

Uploaded by

shammahzuze05
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/ 55

Chapter 1

Data Representation
Chapter Objectives
Learners should be able to:

 convert one number base to another


 multiply and divide binary numbers
 represent binary numbers in twos complement
 normalise floating point binary numbers
 change numbers to binary using character sets
 represent data and character sets
 distinguish arithmetic errors

Introduction
Data representation is concerned with the way data in the computer is processed, stored and even
transmitted. Computers are basically classified as digital, analogue or hybrid. Digital computers
process data in discrete form whereas analog computers process data that is continuous in nature.
Hybrid computers process both discrete data and continuous data. A computer can store different
forms of data which can range from sound, images, videos, numbers or text. Digital computers
process data in two states ON and OFF. The ON state is represented by a “0” and the OFF state is
represented by a “1”. The values “0” and “1” are known as binary digits (Bits)

Number Base Conversion


– This involves converting a number in binary to denary (base 10), octal (base 8) or
hexadecimal (base 16) or vice versa.

(a) Conversion from decimal to binary


– Divide the denary number by 2, listing the remainders until the answer is 0 remainder 1.
– Take the remainders only from the last one until the first.

Example
Convert 21 into binary

2 21
2 10 R 1
2 5 R 0
2 2 R 1
2 1 R 0
0 R 1

We write down the remainders from bottom upwards to get the answer 101012

1
Example
Convert 12.75 into binary

(i) The integer value 12 is converted as usual

2 12
2 6 R 0
2 3 R 0
2 1 R 1
2 0 R 1

– Therefore, 12 in binary is 11002

(ii) The next stage is to convert the decimal fraction .75 to a binary representation

– Multiply the decimal fraction by 2. The whole number part of the result is the first binary
digit to the right of the point.

.75 x 2 = 1.5, the first binary digit to the right of the point is a 1.

So far, we have .75 = .1??? . . . (base 2).

– Next we disregard the whole number part of the previous result (the 1 in this case) and
multiply by 2 once again. The whole number part of this new result is the second binary
digit to the right of the point

.5 x 2 = 1.0, the second binary digit to the right of the point is a 1.

So far, we have .75 = .11?? . . . (base 2).

– We will continue this process until we get a zero as our decimal part or until we
recognise an infinite repeating pattern.
– In fact, we do not need to continue because we had 0 as the fractional part of our result
there.
– Hence the representation of 12.75 = 1100.112.

Infinite binary fractions

– If for example, we are converting a binary fraction to decimal and we notice that the steps
to be performed are exactly the same action we had in the previous steps we are then
bound to have an infinite binary fraction.
– In other words, we will never get a 0 as the decimal fraction part of our result but going
to have a repeating pattern.

– For example, 3.1 converted to binary will produce the following repeating pattern:

11 .00011001100110011 . . . (base 2)

2
0011 is a repeating pattern.
– Therefore, 3.1 in binary will be 11.000112

Example
Convert 5.37510 into binary

(i) The integer value 5 is converted as usual

2 5
2 2 R 1
2 1 R 0
2 0 R 1

– Therefore, 510 in binary is 1012

(ii) The next stage is to convert the decimal fraction .375 to a binary representation

0.375 x2 0.750 (0 becomes the first value after the binary point)
0.750 x2 1.500 (1 becomes the second value after the binary point)
1.500 x2 1.000 (1 becomes the third value after the binary point)
(fractional part becomes 0, so we stop)

– Therefore, 3.37510 = 101.0112

(b) Conversion from Binary to Decimal


– First, write the place values starting from the right to the left hand side, staring at 20.
– Write each digit under its place value.
– Multiply each digit by its corresponding value.
– Add all the products to get the denary equivalent.

Example
Convert 11100 into denary

Power 24 23 22 21 20
Equivalent to: 16 8 4 2 1
Binary Digits 1 1 1 0 0

(1x24) + (1x23) + (1x22) + (0x21) + (0x20)

(1x16) + (1x8) + (1x4) + (0x2) + (0x1)

16 +8+ 4+0+0 = 28.

– Therefore, 111002 to denary is 28.

3
Example
Convert 101.11 into denary

101 = (1x23) + (1x20)


= 8+1
=9
.11 = (1x2-1) + (1x2-2)
= 0.5 + 0.25
= 0.75

101.11 = 9.75 in denary

Example
Convert 1111.11000 into denary

28 27 26 25 24 23 22 21 20 . 21 22 23 24 25
256 128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
0 0 0 0 0 1 1 1 1 .1 1 0 0 0

– The binary number fractional binary number 1111.110000 number represents


8 + 4 + 2 + 1 + 0.5 + 0.25 = 15.7510

– The following shows the equivalent representation of an integer binary number and a
fractional binary number

 Representation of an Integer Binary Number

MSB Binary Digit LSB


28 7 6 5 4 3 2
2 2 2 2 2 2 2 1
20
256 128 64 32 16 8 4 2 1
1 0 1 0 0 0 0 0 0

– The binary number 101000000 represents


256 + 64 = 22010

 Representation of a Fractional Binary Number

28 27 26 25 24 23 22 21 20 . 21 22 23 24 25
256 128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
1 0 0 0 0 0 0 1 1 1 1 1 0 0

– The binary number 100000011.11100 represents

4
256+2+1+0.5+0.25+0.125 = 259.37510

Binary Fraction Place Value Fraction Decimal


-1 1
0.1 2 /2 0.5
-2 1
0.01 2 /4 0.25
-3 1
0.001 2 /8 0.125
-4 1
0.0001 2 /16 0.0625
-5 1
0.00001 2 /32 0.03125
-6 1
0.000001 2 /64 0.015625

Activity 1

1. Convert the following denary numbers into binary


a) 102 b) 6.625

2. Convert the following binary numbers into denary


a) 1111011 b) 11101.0011

(c) Conversion from Decimal to Octal


– Octal means base 8.
– Octal number contains only digits from 0 to 7.
– The same method as used on binary also applies on decimal to octal conversion.
– Take the decimal number, divide it by 8 and then take the remainders only.

Example
Convert 8810 into octal

8 88
8 11 R 0
8 1 R 3
0 R 1

– Therefore, 8810 = 1308

Example
Covert 27 into octal

8 27
8 3 R 3
0 R 3

5
– Therefore, 2710 = 338

Example
Convert 23.015625 into octal

(i) The integer value 23 is converted as usual

8 23
8 2 R 7
0 R 2

– Therefore, 2310 is 278

(iii) The next stage is to convert the decimal fraction .015625 to an octal representation. We
perform the same procedure as we did in binary but in this case we multiply by 8.

0.015625 x8 0.125 (0 becomes the first value after the point)


0.125 x8 1.000 (1 becomes the second value after the point)
(fractional part becomes 0 so we stop)

– Therefore, 23.01562510 = 27.018

(j) Conversion from Octal to Decimal

Example
Convert 1678 into denary

Power 84 83 82 81 80
Equivalent to: 4 096 512 64 8 1
Octal Digits 1 6 7

(1x82) + (6x81) + (7x80)

(1x64) + (6x8) + (7x1)

64 + 48 + 7 = 11910

– Therefore, 1678 to denary is 11910

6
Example
Convert 17.528 into denary

Power 81 80 8-1 8-2


Equivalent to: 8 1 0.125 0.015625
Octal Digits 1 7 5 2

17 = (1x81) + (7x80)
=8+7
= 158
.52 = (5x8-1) + (2x8-2)
= 5/8 + 2/64

= 0.625 + 0.03125

17.528 = 15 + 0.125 + 0.015625


= 15.6562510

– Therefore, 17,528 = 15.6562510

Activity 2

1. Convert the following denary numbers into octal


a) 95 b) 4.65

2. Convert the following octal numbers into denary


a) 177 b) 35.55

(i) Conversion from Decimal to Hexadecimal


– Hexadecimal means base 16.
– A hexadecimal number contains numbers from 0 to 9 and A to F.
– In hexadecimal A is equivalent to 10, B is equivalent to 11, C is equivalent to 12, D is
equivalent to 13, E is equivalent to 14 and F is equivalent to 15.
– The table below illustrates this:

Decimal number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal equivalent 0 1 2 3 4 5 6 7 8 9 A B C D E F

– A hexadecimal number can be denoted using 16 as a subscript or addition of either a 0x


or an h suffix. For example, 56 in hexadecimal can be written as 5616 or 56h or 0x56.
– The same method of divide the number by its base and then take the remainders only as
used on binary and octal conversions also applies on decimal to hexadecimal conversion.

7
Example
Covert 20610 into hexadecimal

16 206
16 12 R 14
0 R 12

– C represents 12 and E represents 14.


– Therefore, 20610 = CE16

Example
Convert 97.3510 into hexadecimal

(k) The integer value 97 is converted as usual

16 97
16 6 R 1
0 R 6

– Therefore, 9710 is 6116

(iv) The next stage is to convert the decimal fraction .35 to hexadecimal representation. We
perform the same procedure as we did in binary and octal but in this case we multiply
by 16.

0.35 x 16 5.6 (5 becomes the first value after the point)


0.6 x 16 9.6 (9 becomes the second value after the point)
0.6 x 16 9.6 (9 becomes the second value after the point)
0.6 x 16 9.6 (9 becomes the second value after the point)
0.6 x 16 9.6 (9 becomes the second value after the point)
(99 is now repeating itself, so we stop)

– Therefore, 97.3510 = 61.5999916

(j) Conversion from hexadecimal to decimal

Example
Convert D116 into denary

Power 164 163 162 161 160


Equivalent to: 65 536 4 096 256 16 1
Octal Digits D 1

(Dx161) + (1x160)

8
(13x16) + (1x1)

208 + 1= 20910

– Therefore, 20816 = 20910

Example
Convert A7.4D16 into denary

Power 161 160 16-1 16-2


Equivalent to: 16 1 0.0625 0.00390625
Hexadecimal Digits A 7 4 D

A7 = (Ax161) + (7x160)
= 160 + 7
= 16716
.4D = (4x16-1) + (Dx16-2)
= (4x16-1) + (13x16-2)
= 0.25 + 0.05078125

A7.4D16 = 167 + 0.25 + 0.05078125


= 167.3007812510

– Therefore, A7.4D16 = 167.3007812510

Activity 3

1. Convert the following denary numbers into hexadecimal


b) 157 b) 89.25

2. Convert the following hexadecimal numbers into denary


a) A2E116 b) 2A.5

(k) Conversion from binary to octal and hexadecimal and vice versa
– A relationship exists between binary, octal and hexadecimal numbers which makes
conversion of binary to octal and hexadecimal and conversion of octal and hexadecimal to
binary to be done straight away with minimum amount of calculations.

 Conversion from binary to octal


– The relationship between binary and octal numbers is that octal (8) is 2 3.
– Thus converting a binary number to octal can be done with much ease by putting the bits
in a group of 3 bits, starting from the right going to the left.
– If the last batch (to the left) does not have 3 bits, append 0s to its left in order to get 3 digits
in each batch.

9
– Convert each group separately to its decimal equivalent, which will automatically be in
base 8.
– Combine the decimal values obtained to obtain the octal value.

Example
Convert 10001110101012 to octal

(i) Group the bits in 3s starting from right going to the left

001 000 111 010 101

(ii) Convert each group separately to its decimal equivalent


001 becomes 1 (in decimal)
000 becomes 0
111 becomes 7
010 becomes 2
101 becomes 5

222120 222120 222120 222120 222120


001 0 00 1 11 010 101
1 0 7 2 5
(iii) Combine the values to obtain the octal number
107258

– Therefore, 10001110101012 = 107258

 Conversion from octal to binary


– Take each digit separately and then convert it to binary by dividing it by 2.
– Put each binary result obtained into 3 bits; if they are not 3 bits append 0s to the left.
– Take the binary digits and combine them into one binary number.

Example
Convert 5278 into binary

(i) Convert each digit separately to binary


5 becomes 101
2 becomes 010 (0 has been added to the left to make them 3 bits)
7 becomes 111

5 2 7
1012 0102 1112

(ii) Take the binary digits and join them into one binary number
101010111

– Therefore, 5678 = 1010101112

 Conversion from binary to hexadecimal


10
– Hexadecimal is a more convenient short hand form to represent data than binary.
– Again, the relationship between binary and hexadecimal numbers is that hexadecimal (16)
is 24.
– Thus binary bits are put in groups of 4, starting from the right going to the left.
– If the last batch (to the left) does not have 4 bits, append 0s to its left in order to get 4 digits
in each batch.
– Each group is then separately converted to its decimal equivalent.
– Combine the values obtained to obtain the hexadecimal values. Remember that A
represents 10, B represents 11, C represents 12, D represents 13, E represents 14 and F
represents 15 in hexadecimal.

Example
Convert 111000111010101 into hexadecimal

(i) Group the bits in 4s starting from right going to the left

111 0001 1101 0101

(ii) Convert each group separately to its decimal equivalent


0101 becomes 5 (in decimal)
1101 becomes D (13)
0001 becomes 1
0111 becomes 7 (0 has been added to the left to make them 4 bits)

23222120 23222120 23222120 23 222120


0111 0001 1101 0101
7 1 D (13) 5

(ii) Combine the values obtained


71 D 516

– Therefore, 1110001110101012 = 71D516

 Conversion from hexadecimal to binary


– Take each digit separately and then convert it to binary by dividing it by 2
– Put each binary result obtained into 4 bits, if not append 0s to the left to make them 4 bits
– Take the binary digits and join them into one binary number.

Example
Convert 5CA16 to binary

(i) Convert each digit separately to binary


5 becomes 0101 (append a 0 to the left to make them 4 bits)
C becomes 1100
A becomes 1010

5 C A
01012 11002 10102

11
(ii) Take the binary digits and join them into one binary number
0101110010102

– Therefore, 5CA1616 = 0101110010102

Activity 4

1. Using a minimum number of calculations, convert the binary number


1000100111101110 to

a) octal b) hexadecimal

2. Using a minimum number of calculations, convert the following numbers to octal


a) 2EF216 b) 7858

Binary System
– Using binary system the data is represented in two possible states, that is, 0 and 1, thus in
base 2.
– Most computing devices use the binary number system to represent electronic circuit
voltage state, which considers 0 voltage input as off and 1 voltage input as on.
– The sequence of ON’s and OFF’s forms the electrical signals that the computer can
understand.
– The 0 or 1 is known as a binary digit.

Bits, Bytes, Nibble and Word


– The word bits, bytes, nibble and word are related to computer memory and data size.
 Bit
– Bit stands for binary digit which can be 0 or 1. A bit is the basic unit of data in digital
computers.
 Nibble
– A nibble is half a byte which is a group of 4 bits, for example, 0110.
 Byte
– A byte is a collection of 8 bits, for example, 011000001. A group of 8 bits represent a
character.
 Word
– A word refers to a number of bits that a particular processor handles at once.
– A word is made up of 2 or more bits.
– The term word length or word size is used to measure the number of bits in each word, for
example, 16 bits, 32 bits, 64 bits etc.
– Thus, word size affects processor speed as a 64 bit processor can process data faster than a
32 bit processor.

Advantages of Binary System

12
– It is easier to construct electric circuits based on only two binary values 0 and 1 or ON and
OFF logic rather than construct devices that can understand natural language due to the
different forms of natural languages.
– Binary data is also reasonable simple to store - again only needing a two state storage
(On/Off).
– Calculations can be carried out using reasonably simple active electronics (simple
transistor circuits), since it only requires on and off (1 and 0) signals.
– All forms of data can be represented in binary system format.
– Digital devices are more reliable, small and use less energy as compared to analog devices.
– Binary codes are suitable for the computer applications and digital communications.

Disadvantages of Binary System


– Difficult for most people to read.
– It takes a lot of digits to represent any reasonable number (for instance to represent value
50, it takes 2 digits in Decimal and 6 digits in Binary).

Binary Arithmetic
– Addition, subtraction, multiplication and division can be performed on binary numbers in
a similar way as we perform the arithmetic operations on denary numbers (base ten).

 Binary Addition
– In decimal addition, if you add 7 + 3 you get 10; in the sum this gives a digit 0 and a
carry of 1.
– Similarly in binary addition when you add 1 and 1; the result is two, written as 10 in
binary, we get, a digit 0 and a carry of 1.
– Therefore in binary:
0+0=0
0+1=1
1+0=1
1 + 1 = 10 (which is 0 carry 1)

Example
100101 + 10101

Explanation

100101
+ 10101
111010

first column (from the right!) : 1 + 1 = 0 carry 1


second column : 0 + 0 + 1 (carried) = 1
third column : 1 + 1 + no carry = 0 carry 1
fourth column : 0 + 0 + 1 (carried) = 1
fifth column : 0 + 1 + no carry = 1

13
sixth column : 1 + 0 + no carry = 1

– Therefore, the answer is 1 1 1 0 1 02

Example
Find the sum of the binary numbers 10111 and 110101

11111 Carry
10111
+ 110101
1001100

Example
Find the sum of the binary numbers 10001 and 11101
1 1 Carry
10001
+ 11101
101110

 Binary Subtraction
– Just like in decimal subtraction, if you must subtract a one from a zero, you need to
“borrow” from the left.

Example
1011011 − 10010 = 1001001:

1011011
− 10010
1001001

Example
1010110 − 101010

0 0
1 10 1 10 1 1 0
− 1 01 010
1 01 100

 Binary Multiplication
– Binary multiplication is actually much simpler to calculate than decimal multiplication.
– In the case of decimal multiplication, we need to remember 4 x 9 = 36, 7 x 7 = 49, and so
on.
– In binary multiplication, we only need to remember the following:

14
0x0=0
0x1=0
1x0=0
1x1=1

Example
Multiply 101 by 11

1 1 0 1
x 1 1

Explanation

First we multiply 1101 by 1, which produces 1101. Then we put a 0 as a placeholder as we


would in decimal multiplication, and multiply 1101 by 1, which produces 1101.

1 1 0 1
x 1 1
1 1 0 1
1 1 0 1 0 The 0 is the placeholder

The results from our previous step indicates that we must add 1101 and 11010, the sum of which
is 100111.

1 1 0 1
x 1 1
1 1 0 1
1 1 0 1 0
1 0 0 1 1 1

Example

Multiply 1011.01 by 1.1

1 0 1 1. 0 1
x 1. 1
1 0 1 1 0 1
1 0 1 1 0 1 0
1 0 0 0 0 .1 1 1

– We multiply the binary numbers as we do in decimal. On the result we then count the
number of digits after the binary point in the two binary numbers.

15
– In our example the first number has two digits after the binary point and the second
number has one digit after the binary point.
– Therefore, the final result will have three digits after the binary point.

Activity 5

Find the product of the following binary numbers

(i) 101 and 10


(ii) 1100 and 11
(iii)1011.01 and 110.1

 Binary Division
– Binary division involves knowledge of binary multiplication.

Example

1011 divided by 11.

11 R 10
11 )1011
-11
101
-11
10 <-- remainder, R

OR

1011 divided by 11.

11.101010
11 )1011.000000
-11
101
-11
100
-11
100
-11
100
-11
10

– To get a fractional value, add a binary point immediately to the right of the fourth bit
from the left and append a 0 bit. Bring down the 0 bit.
– In the above example, the binary fraction repeating is 10 and it will continue. So it’s
better to stop at four or six fractional bit places and settle for 11.1010 or11.101010

16
1011 /11 = 11 R 10

To check our answer, we first multiply our divisor 11 by our quotient 11. Then we add its'
product to the remainder 10, and compare it to our dividend of 1011.

11
x 11
11
+ 11
1001 <-- product of 11 and 11

1001
+ 10
1011 <-- sum of product and remainder

Example
10111 divided by 10

101_ R=1
10 )1011
-10
11
-10
1<-- remainder, R

Example
10.111 divided by 0.10
Step 1
Remove the binary point from the divisor by moving it two steps to the right.
0.10 becomes 010
Step 2
We must also move the binary point same number of steps to the right as we did on the divisor.
Remember to add 0 bits as needed to fill the new spaces.
10.111 becomes 1011.1
Step 3
Discard/ignore the leading zeros on the divisor. Then continue with the division using the two
binary numbers as follows:
1011.1 / 10

17
101.11_
10 )1011.1
-10
11
-10
11
-10
10
-10

Activity 6

Work out the following:


(i) 100 / 10
(ii) 111/11
(iii)11.01/1.1
(iv) 10.11/0.010

Octal Arithmetic
– The addition and subtraction of octal numbers follows the same rules as the addition and
subtraction of numbers in any other number system.
– The only difference is in the borrowed number. In the decimal system, you borrow a
group of 1010. In the binary system, you borrow a group of 2 10. In the octal system you
borrow a group of 810.

Advantages of Octal Representation


– Easier to work with and read than binary.
– Conversions of octal to and from binary are straight forward.

Octal Addition
Example
168 + 58

1 Carry
16
+ 5
23

18
Example
2568 + 2238

11
Carry
256
+223
501

Octal Subtraction
Example
3568 -2738

1 8 Borrow
2
356
-2 73
63

Example
6548 - 1368

8 Borrow
6 45 4
-13 6
51 6

Hexadecimal Arithmetic
– The addition and subtraction of hexadecimal numbers also follows the same rules as the
addition and subtraction of numbers in any other number system.
– The only difference is in the borrowed number. In hexadecimal system, you borrow a
group of 1610.
Uses of Hexadecimal
– To store instructional codes in the computer.
– To represent locations of data in memory (memory addresses).
– To represent web pages colours, for example, #FF0000 represents a red colour.

Advantages of Hexadecimal Representation


– Easier to work with and read than a chain of binary digits.
– Easy to convert hexadecimal to and from binary.
Hexadecimal Addition
– Remember the following when dealing with hexadecimal arithmetic:

19
Decimal number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal equivalent 0 1 2 3 4 5 6 7 8 9 A B C D E F

Example
4C616 + 2B216

1 Carry
4C6
+2B2
77 8
Example
4C616 + 2B216

1 Carry
4C6
+2B2
77 8

Hexadecimal Subtraction
Example
3568 -2738

1 8 Carry
2
356
-2 73
63

Example
3A516 -1B216

16 Carry
2
3A 5
-1 B 2
1 F 3

Activity 7

Work out the following:


(i) 8B16 + 2516
(ii) 12716 + 5C16
(iii) 48E16 – A416
(iv) BB216 – 6D16

20
(v) 678 + 258
(vi) 1248 + 2718
(vii) 5148 – 278
(viii) 4628 – 768

Integer Representation
– Computers use a fixed number of bits to represent an integer, for example, 8-bit, 16-bit,
32-bit or 64-bit.
– Two representation schemes are used for integers:
a) Unsigned integers: can represent zero and positive integers.
b) Signed integers: can represent zero, positive and negative integers.

– The following are used to represent signed integers:


a) Sign-Magnitude
b) 1's Complement
c) 2's Complement

 Sign and Magnitude


– Sign and Magnitude uses the most significant bit in a binary number to represent the sign
of the binary number.
– The remaining bits in the number indicate the magnitude (or absolute value).
– In a byte with eight bits, the left most bit is the sign bit and the remaining seven bits
represents the magnitude of the number.
– The range of numbers that can be represented by sign and magnitude is obtained using the
following formulae:

(-2n ) to (+2n-1)
where n is the number of bits excluding the sign bit

0 1 1 1 1 1 0 0
Sign bit Magnitude
Example
Using 8 bits, find the range of numbers that can be represented using sign and magnitude

(-2n ) to (+2n-1)

(-27 ) to (+27-1) n = 7 not 8 because the other bit is for the sign bit

(-128) to (+128-1)

-128 to +127

– Thus, an 8-bit signed number can represent data in the range -12810 to +12710.

21
Example
Using 8-bits represent 15 in sign and magnitude

Sign bit: 0
Magnitude: 0001111

– Therefore, 15 in sign and magnitude using 8-bits is 00001111

Example
Using 8-bits represent -20 in sign and magnitude

Sign bit: 1
Magnitude: 0010100

– Therefore, -20 in sign and magnitude using and 8-bits is 10010100

Representation of zero (0) using sign and magnitude


– Zero (0) is set for a positive number or positive zero and one (1) is set for a negative number
or negative zero.
– Using sign and magnitude zero (0) has two representations; 10000000 (-0) and 00000000
(+0).
– Since -0 and +0 are both just 0, it is very strange to have two different representations for the same
number. This is one of the reasons that a simple sign bit is not used in practice.

 1s Complement
– 1s complement can be used to represent both positive and negative numbers.
– Positive numbers do not change and they are represented as usual.
– If a number is negative we can represent it using one’s complement by applying the bitwise
NOT to the number.
– Bitwise NOT is an operation on only one operand that performs logical negation on each
bit. For example, the bitwise Not of 10102 is 01012.
– Simply, in one’s complement, 0s are negated to 1s while 1s are negated to 0s.
– The range of numbers that can be represented in 1’s complement is found by the formula:

- (2n-1-1) to + (2n-1-1)
where n is the number of bits to represent the number
Example
Using 4-bits, find the range of numbers that can be represented using 1s complement.
- (2n-1-1) to + (2n-1-1) n = 4

- (24-1-1) to + (24-1-1)

- (23-1) to + (23-1)

22
- (8-1) to + (8-1)

-7 to +7

– Therefore, the largest number that can be represented is +7 and the smallest is -7.

Example
Using 8-bits represent (i) -10 and (ii) -2 (iii) +7 in 1’s complement
(i) +10 = 000010102
-10 = 111101012

(ii) +2 = 000000102
-2 = 111111012

(iii) +7 = 00001112
-7 = 11110002

– However, 1s complement has two different representations for zero (0):


+0 = 000000002
-0 = 111111112

Addition in 1s Complement
– Addition is performed by doing the simple binary addition of the two numbers.

Example
Using 8 bits, find the sum of 4 and 3

4 00000100
+3 00000011
--- ------------
7 00000111

Subtraction in 1s Complement
– The main purpose of using ones complement in computers is to perform binary subtraction.
– Subtraction is achieved by first performing the 1s complement operation on the number
being subtracted then adding the two numbers.

Example
Using 8-bits, find 8 – 4 in ones complement

(i) Rewrite the problem as 8 + (-4).


(ii) Convert -4 into one’s complement 8-bits equivalent.
4 = 000001002
-4 = 111110112
(iii) Add the binary equivalent of 8 to one’s complement of -4.

23
8 000010002
+ (-4) 111110112
[1]000000112
12 Overflow bit is added to give the answer 000001002
4 000001002

 2s Complement
– Modern computers use two’s complement to represent positive and negative numbers in
binary.
– The useful part of two’s complement is that it automatically includes the sign bit.

Advantages of 2s Complement
– Twos complement allows a computer to add and subtract numbers using the same operations
without a need for circuitries to examine the sign of an operand (not need to implement
adders and subtractors).
– Zero has only a single representation, unlike in ones'-complement where it has two values
11111111 (-0) and 00000000 (+0).
– Twos complement enables higher precision arithmetic to be handled.

– The two's complement notation is characterised as follows:

(i) A fixed number of bits are used to represent numbers


(ii) The most significant bit is called the sign bit
(iii) This same notation is used to represent both positive and negative numbers

2s Complement representation of a positive number


– Positive numbers are represented normally.
– Convert the number to binary.

Example
Using 4-bits represent 7 in 2s complement

7 = 101

To make them 4 bits prefix the result with a 0

– Therefore, 7 = 01012

Example
Using 8- bits represent 9 in 2s complement

9 = 10012

Put four 0s to the left to make them 8 bits

– Therefore, 9 = 000010012

2s Complement representation of a negative number

24
– Negative numbers are represented using a 2's complement form.
– To obtain the 2's complement of a number:

Method 1
(i) Convert the number to its binary equivalent, if it is not in binary.
(ii) Change the number to one’s complement (Change the 0’s to 1s and 1s to 0s)
(iii) Add 1 to the result

Method 2
(i) Write the bits starting from the right hand side.
(ii) Take all 0s as they are at their respective position including the first 1 value
encountered in the binary number.
(iii) Thereafter change 1s to 0s and 0s to 1s to get the 2’s complement of the number.

Example
Using 4 bits represent (i) -7 and (ii) -3 in two’s complement

(i)
+7 01112
1s complement 10002
Add 1 + 1
10012

-7 = 10012

(ii)
+3 00112
1s complement 11002
Add 1 + 1
11012

-3= 11012

Representation of zero (0) in 2s Complement

– There is no such thing as negative zero (-0).


– We can convert anyway 0 = 00000000 –> 11111111 + 1 = 1 00000000.
– We still arrive at 0 in binary for the eight relevant bits.
– Ignore the ninth carry bit to get 00000000.
– Therefore, 0 has only one representation, that is, 00000000.

Addition in 2s Complement
– Addition is performed by doing the simple binary addition of the two numbers.

Example

25
Using 5- bits, find the sum of 9 and 5

9 010012
+5 001012
14 011102

Subtraction in 2s Complement
– Subtraction is achieved by first performing the 2s complement operation on the number being
subtracted then adding the two numbers.

Example
Using 8-bits, find 25 - 29

This is the same as 25 + (-29)

25 0001 10012
+ (-29) 1110 00112 (+29 = 0001 11012)
-4 1111 1100 2

Example
Using 4-bits, find 6 – 6

This is the same as 6 + (-6)

6 01102
+( -6) 10102
0 [1]00002
Overflow bit is thrown away to give answer as 0000 which is 0.

Example

Using 4-bits, find -63-94

This is the same as -63 + (-94). Therefore, convert -63 and -94 into 2s complement and add the
two numbers.

(-63) 110000012
+(-94) 101000102
[1] 011000112

– Throw away the carry bit 1, to get the final answer as 01100011.
– The extra bit 1 indicates overflow.
– The result above indicates overflow as the result of adding two negative numbers cannot
give a positive answer.

Converting from binary 2s Complement to denary

– The first thing is to determine whether the number is positive or negative.


– For positive numbers, we can simply convert the binary number back to decimal.

26
– For negative numbers, we first convert it back to a normal binary number and then prefix
the denary number with a negative (-) sign.
– A positive number starts with a zero (0) and a negative number starts with a one (1)
– The process of converting from binary 2s complement to denary is accomplished using the
following steps:

(i) Complement the binary number (Convert zeros to ones and ones to zeros)
(ii) Add one to the binary number
(iii) Convert binary number to decimal
(iv) Prefix a minus sign

OR

(i) Subtract 1 from the binary number


(ii) Invert all the digits (Convert zeros to ones and ones to zeros)
(iii) Convert the resulting binary number to decimal
(iv) Add a minus sign in front of it.

Example

Convert the 2s complement binary number 010000012 to denary

The number is positive because it starts with a zero (0).

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
0 1 0 0 0 0 0 1

= 64 + 1
= 65

Example

Convert the 2s complement binary number 111000102 to denary.

The number is negative because it starts with a one (1).

11100010
Complement the number 00011101
Add 1 +1
00011110

Convert the binary to decimal 30


Prefix a minus sign -30

Range of numbers represented in 2s Complement

27
– With twos complement representation there is no bit allocated as the sign bit but the left-
most bit behaves like one.
– Unsigned range refers to how many numbers you can represent if you only allow positive
numbers (no sign is needed).
– Signed range refers to how many numbers you can represent if you require both positive
and negative numbers.
– Therefore, twos complement range is a signed range since it represents both positive and
negative numbers.
– For example, the range of 8-bit values if they are stored using unsigned numbers will be
from 00000000 (0) to 11111111 (255), while the signed two's complement range is from
10000000 (-128) to 01111111 (127).
– The following formulae can be used to find the largest number and smallest number that
can be represented in 2s complement:

- (2n-1) to + (2n-1-1)
where n is the number of bits used to represent the number

Example
Find the largest number that can be represented in 8-bit 2s complement

- (2n-1) to + (2n-1-1)
- (28-1) to + (28-1-1)
- (27) to + (27-1)
-128 to + 127

– Therefore, and the smallest number is -128 = (100000002 ) and the largest number is
127 = (011111112).
– Using 8-bits to represent a number, if the result of calculation produces a result above +127
then it is called overflow.
– If the result produced is less than -128 then it is called underflow.

Activity 8

1. Using 8-bits represent the decimal number -28 in


(a) Sign and magnitude
(b) 1s complement
(c) 2s complement

2. Using 4-bits what is the largest and smallest numbers that can be represented in
(a) sign and magnitude
(b) 1s complement
(c) 2s complement

3. Using 8-bits perform the following calculations using


(a) 1s complement
(b) 2s complement
(i) 28 + 2

28
(ii) 14 – 8
(iii) -21- 8

Fixed Point Arithmetic


– The term ‘fixed point’ refers to the corresponding manner in which numbers are
represented, with a fixed number of digits after, and sometimes before, the decimal point.
– For example, a fixed-point representation with a uniform decimal point placement
convention can represent the numbers 126.45, 1264.56, 12645.67, etc with two digits after
the decimal point.

Fixed Point Binary Number System


– The fixed point number representation assumes that the binary point is fixed at one
position.
– The binary point is not actually present in the register, but its presence is assumed based
on whether the number which is stored is a fraction or an integer.
– Thus fixed point numbers can either be fractional or integer.

 Fixed Point Integer Representation


– The register used to store an integer value will be as follows:

* * * * * * * *

– There is no memory space for the binary point.


– However, computers represent a finite number of digits and this limitation allows us to
evaluate the maximum and minimum possible numbers that can be represented.

Maximum Positive Number

Positive numbers start with a 0, thus 01111111 = +127

Minimum Positive Number

This evaluates to 00000001 = +1

Smallest Magnitude Negative Number:-

Negative numbers start with a 1. This gives us 11111111 = -1

Largest Magnitude Negative Number

This is 10000000 = -128

Range of numbers that can be represented

The overall range of numbers that can be represented is given by the following formulae:

-2n-1 to 2n-1-1

29
where n is the number of bits to represent the number

Example
Using 8-bits, find the range of numbers that can be represented

-2n-1 to 2n-1-1

-28-1 to 28-1-1

-27 to 27-1

-128 to + 127

 Fixed Point Fractional Binary Numbers


– The decimal point is fixed at one position and therefore does not move.
– Given one byte to hold each number, and assuming that there are 7 bits after the
imaginary binary, the fractional binary number may be shown as below

1 0 1 1 0 1 1 1

Binary point

– The following shows an 8-bit fixed point fractional binary number with an imaginary
binary point after the fifth digit
10001001

Imaginary fixed binary point

Maximum Positive Number

This becomes 0.1111111 = 1- 1/128 = 0.9921875

Minimum Positive Number

This evaluates to 0.0000001 = 1/27=0.0078125

Smallest Magnitude Negative Number

This gives us 1.1111111 = -1/27=0.0078125

Largest Magnitude Negative Number

This gives us 1.0000000 = -1

– Using 2s complement negative numbers start with a 1 and positive numbers start with a 0.

30
Example

Using 1 byte to hold each number, with an imaginary binary point fixed after the fourth digit,
convert the decimal number 8.5 to binary.

8 = 1000
.5 = .1

=1000 1000 (Three 0s added to make it one byte)

Example
Assuming 3 bits after the imaginary binary point, convert the binary number 0000011011 to
decimal.
0000011011

Imaginary fixed binary point

0000011.011

26 25 24 23 22 21 20 . 21 22 23
64 32 16 8 4 2 1 0.5 0.25 0.125
0 0 0 0 0 1 1 .0 1 1

= 2 + 1 + 0.25 + 0.125
= 3.375

Example

Represent -7.2510 in 8-bit binary with the binary point after the fourth digit.

Hint: With a negative number we have to apply twos complement always.

23 22 21 20 . 2-1 2-2 2-3 2-4


8 4 2 1 0.5 0.25 0.125 0.0625
Step-1
Calculate the positive equivalent 7 . 2 5
number in binary.
0 1 1 1 . 0 1 0 0
Step-2
Change 0s to 1s 1 0 0 0 . 1 0 1 1
and 1s to 0s (Complement).
Step-3
1
Add 1 to the result.
1 0 0 0 . 1 0 1 1

31
Advantages of the Fixed Point Binary System

– It preserves accuracy as required.


– It is easy to convert.

Disadvantages of the Fixed Point Binary System

– It has a limited range.


– Very small numbers and very large numbers cannot be represented.

Floating Point Arithmetic


– The term floating point is derived from the fact that there is no fixed number of digits
before and after the decimal point; that is, the binary point can be placed anywhere (float)
relative to the significant digits of the number.
– Floating point representation can handle a wide range of numbers, for example, a fixed-
point representation with a uniform decimal point placement convention can represent the
numbers 123.45, 1234.56, 12345.67, etc, whereas a floating-point representation could in
addition represent 1.234567, 123456.7, 0.00001234567, 1234567000000000, etc.

 Mantissa and Exponent


– The floating point representation of a number has two parts namely mantissa and
exponent.
– The mantissa is the significant digits of a number in scientific notation or in floating-point.
– The exponent shows the position of the binary point in the mantissa. It tells us how many
places to move the point to the right or to the left so as to get the original value.
– If exponent is positive we move the point to the right. If the exponent is negative we move
the binary point to the left.
– Consider the number 723: it can be written using exponential notation as:

1. 7.23 x 102
2. 72.3 x 101
3. 723 x 100
4. 0.723 x103
5. 7230 x 10-1

0.723 x 103

Mantissa Exponent
– This means we need only store the mantissa 0.723 and the exponent 3 means we move
the decimal point three places to the right.

Now the same with Binary Floating Point Representation

32
– The same can be done in binary and this forms the foundation of our floating point
number.
– The floating point number will be represented as follows:

Mantissa x 2Exponent

– Since we need only to store the mantissa and exponent the binary floating number is
represented as follows:

Mantissa Exponent

– Using 8-bits for the mantissa and 4-bits for the exponent the binary number 0.0001111can be
represented as follows:
(i) 0.0001111 x 20
00001111 0000 (Mantissa: 00001111 Exponent: 0000)
(ii) 0.0011110 x 2-1
00011110 1111
(iii) 0.0111100 x 2-2
00111100 1110
(iv) 0.1111000 x 2-3
01111000 1101

 Converting a binary number into Floating Point representation


Example
Represent the binary number 01110.11 in floating point with an 8-bit mantissa and 5-bit
exponent

Move the binary point 4 steps to the left to get 0.111011

The exponent becomes 4 since we have to move the binary point 4 steps to the right to get back
to the original binary number.

0.111011 x 24 (000100)

Append a 0 on the mantissa to make the number of bits 8.


Mantissa: 01110110 (The left most 0 indicates that the number is positive)
Exponent: 00100

01110110 00100

Example
Represent the binary number 11110 in floating point with a 6-bit mantissa and 5-bit exponent.

33
Move the binary point 5 steps to the left to get 0.11110

The exponent becomes 5 since we have to move the binary point 5 steps to the right to get back
to the original binary number

0.11110 x 25 (00101)

Mantissa: 011110
Exponent: 00101

011110 00101

 Converting a denary number into Floating Point Representation

The following are the stages to follow when converting a denary number into binary floating
point:

1. Work out the binary equivalent of the denary number.


2. If it is a negative number perform 2s complement.
3. Work out how far to move the binary point .
4. Set the exponent to be reverse of the number of places you move d the
binary point
5. P a d t he nu m be r w it h e xt r a bi t .

Example
Convert the denary number 39.75 into binary floating point.

27 26 25 24 23 22 21 20 . 21 22 23
128 64 32 16 8 4 2 1 0.5 0.25 0.125
0 0 1 0 0 1 1 1 .1 1 0

00100111.110

Move the binary point 6 steps to the left to get the following:
00.100111110

To get our decimal point back to where it started, we need to move 6 places to the right (6 now
becomes the exponent)
0.100111110 000110

Therefore, 39.7510 = 0100111110 000110 in binary floating point

Example
Convert the denary number -13. 25 to a floating-point binary representation with 8-bits for the
mantissa and 4-bits for the exponent.

First convert 13.25 to binary

34
24 23 22 21 20 . 21 22 23
16 8 4 2 1 0.5 0.25 0.125
0 1 1 0 1 .0 1 0

Perform 2s complement since it is a negative denary number (-13.25).


01101.010 becomes 10010.110

Move the binary point 4 steps to the left to get the following:
1.0010110

To get our decimal point back to where it started, we need to move 4 places to the right.
Therefore, 4 now becomes the exponent.

1.0010110 0100

Therefore, -13.2510 = 10010110 0100 in binary floating point

 Converting a Floating Point Number into denary.


The following are the stages to follow when converting a denary number into binary floating
point:

1. Find the sign of the mantissa (make a note of this).


2. Find the value of the exponent and whether it is positive or negative.
3. Move the decimal the distance the exponent asks, left for a negative exponent,
right for a positive exponent.
4. If the mantissa is negative perform twos complement on it.
5. Starting at the decimal point work out the values of the mantissa.
6. Refer back to the sign you recorded on the sign move.

Example
A number is represented as an 8 bit floating point number. 5-bits are used as the mantissa and
3- bits are used as the exponent. Both the mantissa and the exponent are in twos complement.
Show the following floating point in its denary equivalent:

a) 01111 011
b) 11000 110

a) 01111 011

01111 011

Mantissa: 01111 (0 means its positive)


Exponent: 011 (0 means its positive)

35
The exponent is 011 (3 in denary)
Therefore, move three steps to the right to get the original binary number
01111 becomes 111.1

Convert 111.1 to denary

22 21 20 . 21
4 2 1 0.5
1 1 1 .1

111.1
= 4 + 2 + 1 + 0.5
= 7.5

b) 11000 110

11000 110

Mantissa: 11000 (1 means its negative)


Exponent: 110 (1means its negative)

Perform 2s complement on the mantissa since it is negative


11000 becomes 01000

The exponent is 110 (-2 in denary). Therefore, move 2 steps to the left to get the original binary
number
01000 becomes 00010

Convert 0.0010 to denary

20 . 2-1 2-2 2-3


0 0.5 0.25 0.125
0 .0 0 1

= 0 + 0+ 0 + 0.125
= 0.125
= -0.125 (Since the mantissa is negative)

Advantages of Floating Point Representation


– Floating point representation has the ability to represent very small numbers and very large
numbers.
– They can handle a larger range of numbers.

Disadvantages of Floating Point Representation


– Floating point representations generally are slower and less accurate than fixed-point
representations.
– Lose a little bit of accuracy however when dealing with very large or very small values

36
– A number can have different representations, for example, in binary, 0.0001111can be
written as follows:
00001111 0000
00011110 1111
00111100 1101

Activity 9
1. A number is represented as an 8 bit floating point number. 5 bits are used as the mantissa and
3 bits are used as the exponent. Both the mantissa and the exponent are in twos complement.
Show the following floating point in their denary equivalent:
(a) 11111 011
(b) 01011 111

2. Work out the binary floating point for the denary number 97, using 10 bits for the mantissa
and 6 bits for the exponent.

Normalisation of Floating Point Numbers


– Normalisation is the process of moving the binary point so that the first digit after the point
is a significant digit. This is done to simplify operations and expressing numbers in
standard form.
– A normalised number is expressed in two main parts, namely the mantissa and the
exponent.
 The Mantissa is always a fraction. The left most bit of the mantissa is a sign bit.
 The binary point is always between the Sign bit and the MSB.
 The Exponent is always an integer and can be positive or negative depending on its sign
bit. The left most bit of the exponent is a sign bit.

– For a floating point binary number to be normalise, the first two bits must be different.
That is:
1.0 or 0.1 and definitely NOT 1.1 or 0.0

– Thus, if the mantissa is positive, the Sign Bit is always 0 and the MSB is always 1(0.1).
– If the mantissa is negative, the Sign Bit is always 1 and the MSB is always 0(1.0).
– For a negative number, there must be NO leading 1s to the left of the MSB, except the sign
bit.

37
1.1100111

– For a positive number, there must be NO leading 0s to the left of the MSB, except the sign
bit.

0.0101111

– With positive numbers, the binary point in the mantissa is always placed immediately
before the first non-zero digit because it allows us to use the maximum number of digits.
– Zero cannot be represented in normalised form. This is because 0.0000000 the first two
digits are the same.
– A normalised value must have the first two bits of the mantissa different. Usually, the
computer uses the smallest positive number to represent zero.
– To maximise the precision of a positive number you should have a mantissa with no
leading zeros.
– To maximise the precision of a negative number you should have a mantissa with no
leading ones.

 Normalising a Floating Point Number


Example
(a) Normalise the following floating point number 0.010000000 | 000011

Convert the exponent to denary.


The exponent is positive.
000011 is 310

The mantissa is positive. The number starts with 0.01 and we need to change this so that it starts
with 0.1for it to be normalised. To do this we need to move the binary point one position to the
right. We must subtract one from the exponent to compensate for the movement of the decimal
place one place left.

So it becomes 0.100000000 x 23-1


0.100000000 x 23-1(000011 -000001)
0.100000000 x 22(000010)

0.100000000 | 000010

Or

0.010000000 | 000011 = 0.100000000 | 000010 (000011 - 000001)


-1 is to compensate for the movement of the binary point one place to the left

Therefore, 0.100000000 | 000010 is the normalised floating point number.

38
(b) Normalise the following floating point number 1.110000000 | 111110

Convert the exponent to denary.


The exponent is a negative number, therefore perform 2s complement.

111110 becomes 000010


000010 = 2
111110 = -2 in denary

The mantissa is also negative. It starts with 1.11 and we need to change this so that it starts with
1.0 for it to be normalised. To do this we need to move the binary point two positions to the right.
We must subtract two from the exponent to compensate for the movement of the decimal place
two places left.

So it becomes 1.000000000 x 2-2-2


1.000000000 x 2-2-2 (111110-000010)
1.000000000 x 2-4(111100)

1.000000000 | 111100

Therefore, 1.000000000 | 111100 is the normalised floating point number.

 Normalising a Binary Number


Example
Using 8 bits for the mantissa and 6 bits for the exponent, normalise the binary number
0.000101011

Move the binary point 3 positions to the right to get the following:
0.101011
Compensate for the number of bits by appending two 0s to get the following:
0.10101100

The exponent becomes -3 since the binary point has to move 3 steps to the left to get back to the
original binary number.

0.1010110 x 2-3(111101) (-3 is 111101 in twos complement)

Therefore, 0.000101011 becomes 01010110 111101 in normalized form.

Example
Using 8 bits for the mantissa and 5 bits for the exponent, normalise the binary number
011101.11

Move the binary point 5 positions to the left to get the following:
0.1110111

The exponent becomes 5 since the binary point has to move 5 steps to the right to get back to the
original binary number.

39
0.1110111 x 23(00101)

Therefore, 011101.11 becomes 011110111 00101 in normalised form.

 Converting a Normalised Number to Denary


Example
Convert the following normalised number to decimal
010000 1100

Mantissa: 010000
Exponent: 1100

The mantissa is positive and the exponent is negative

Convert the negative 2s complement exponent so that it becomes 0100 (4)


Since it is a negative it becomes -4

Move the imaginary binary point 4 steps to the left


0.10000 becomes 0.00001
Convert 0.00001 to denary

20 . 2-1 2-2 2-3 2-4 2-5


1 0.5 0.25 0.125 0.0625 0.028571
0 .0 0 0 0 1

Therefore, 010000 1100 = 0.028571 in denary

Example
Convert the following normalised number to decimal
1011000 1110

Mantissa: 1011000
Exponent: 1110

The mantissa is negative and the exponent is negative

Convert the negative 2s complement mantissa so that it becomes 0101000

Convert the negative 2s complement exponent so that it becomes 0010 (2)


Since it is a negative it becomes -2

Move the imaginary binary point 2 steps to the left


0.101000 becomes 0.001010

Convert 0.001010 to denary

20 . 2-1 2-2 2-3 2-4 2-5 2-6

40
1 0.5 0.25 0.125 0.0625 0.03125 0.015625
0 .0 0 1 0 1 0

1/8 + 1/32 = 5/32


0.125+ 0.03125 = 0.15625

Since the mantissa is negative it becomes -0.15625

Therefore, 1011000 11100 = - 0.15625 in denary

Example
Convert the following normalised number to decimal
010101 0100

Mantissa: 010101
Exponent: 0100

The mantissa is positive and the exponent is positive

The exponent is 4 in denary

Move the imaginary binary point 4 steps to the right

0.10101 becomes 1010.1

Convert 1010.1 to denary

24 23 22 21 20 . 2-1
16 8 4 2 1 0.5
0 1 0 1 0 .1

8 + 2 + 0.5 = 10.5

Therefore, 010101 0100 = 10.5 in denary

 Converting a Denary Number into a Normalised Floating Point Number


Example
Normalise 1/4, given it has 6 bits for the mantissa and 4 bits for the exponent.

Convert the fraction ¼ to binary:

20 . 2-1 2-2
0 0.5 0.25
0 .0 1

0.01

41
Append three 0s to make the mantissa 6 bits.
0.01000

Move the binary point 1 step to the right


0.10000

The exponent becomes 1111 (-1 in denary since the binary point must move 1 step to the left to
get back to the original value)

Therefore, 1/4 becomes 010000 1111 in normalised floating point.

Example
Change the decimal fraction -5.25 to normalised floating point number using 8-bits mantissa and
4-bits exponent.

Convert the fraction -5.25 to binary ignoring the negative sign to get the following:

22 21 20 . 2-1 2-2
4 2 1 0.5 0.25
1 0 1 .0 1

101.01

Move the binary point 3 steps to the left

0.1010100 (add 2 zeros to get 8 bits for the mantissa)

The exponent becomes 0011 (3 in denary since the binary point must move 3 steps to the right to
get back to the original value)

Since the number is a negative one convert 0.1010100 to twos complement


1.0101100

Therefore, -5.25 becomes 10101100 0011 in normalised floating point.

Example
Normalise -1/8, given it has 6 bits for the mantissa and 4 bits for the exponent.

Convert the fraction -1/8 to binary ignoring the negative sign to get the following:

20 . 2-1 2-2 2-3


1 0.5 0.25 0.125
0 .0 0 1

0.001

Append two 0s to make the mantissa 6 bits.

42
1
/8 = 0.00100

Perform 2s complement on the mantissa since it is a negative number.


-1/8 becomes 1.11100

Move the binary point 3 steps to the right


1.00000 (add 3 zeros to get 6 bits for the mantissa)

The exponent becomes 1101 (-3 in denary since the binary point must move 3 steps to the left to
get back to the original value)
Therefore, -1/8 becomes 100000 1101 in normalised floating point.

Advantages of Normalisation
– Ensures that a single representation of a number is maintained (standardisation).
– Ensures maximum possible accuracy is maintained with a given number of bits.
– Saves space by using the space given in an efficient way.
– Can be used to detect error conditions such as underflow and overflow
– Tries to maximise the range of numbers that can be represented in a fixed point
representation (range and accuracy is limited in fixed point representation).

 Range and Precision/Accuracy of Normalised Floating Point Binary Numbers


– The size of the exponent determines the range of numbers that can be represented.
 Increasing the number of bits in the exponent increases the range but this will also
decreases precision.
 Reducing the number of bits in the exponent will reduce the range but this will also increase
accuracy because more digits are represented after the binary point.
– The size of the mantissa determines the precision of the numbers that can be represented
 Precision can be increased by increasing the number of bits that are used to represent the
mantissa but this will decrease the range.
– The only way to increase both range and precision is to use more bits.
– If we use more bits for the mantissa we will have to use fewer bits for the exponent and
vice versa.

Number Ranges in Floating Point Representation


– Let us start off by using 8 bits for the mantissa and 8 bits for the exponent for explanations
below:

Table 1: Number ranges in Binary Floating Point Representation

43
– The largest positive value we can have for the mantissa is 0.1111111.
– The largest positive number we can have for the exponent is 01111111.
– This means that we have 0.1111111 x 21111111 = 0.1111111 x 2127.
– This means that the largest positive number is almost 1 x 2 127.
Also:
– The smallest positive mantissa is 0.1000000.
– The smallest negative exponent is 10000000.
– This represents 0.1000000 x 210000000 = 0.1000000 x 2-128 which is very close to zero;
in fact it is 2-129.

On the other hand:


– The largest negative number (i.e. the negative number closest to zero) is
1.0111111 x 210000000 = -0.1000001 x 2-128.
– We cannot use 1.1111111 for the mantissa because it is not normalised. The first two digits must
be different.
Furthermore:
– The smallest negative number (i.e. the negative number furthest from zero) is 1.0000000 x 2 01111111
= -1.0000000 x 2127 = -2127.

Activity 10
1. Using 10-bit mantissa and a 6-bit exponent, normalise the following numbers:

(a) 0 000011100 001110


(b) 1 101110010 000011

2. What is the decimal value for the following binary patterns if the first 8 bits is the mantissa
and the last 4 bits are the exponent?

44
(a) 10101100 0110
(b) 0101 0000 1100

3. Using 10-bit mantissa and 6-bit exponent, represent the following decimal numbers using
normalised floating point representation:
(a) 25.275
(b) -8.5
(c) 143

Computer Arithmetic Errors


 Round-Off Errors
– Rounding is expressing a number to the nearest whole/decimal/binary number. For
example 3.9569 rounded to 3 decimal places is 3.957. If rounded to the nearest whole
number, it becomes 4.
– Often we cannot represent a denary fraction exactly even if we allow many bits in memory.
Therefore, the number stored is "rounded off" to the closest possible binary equivalent.
– In rounding, the least significant bit may be increased depending on digits removed. The
result should represent the value that is nearest to the original value. For example,

100.1 = 100 (Rounded-off to 2 significant figures)


11011 = 11000 (Rounded-off to 2 significant figures)
11.101 = 100 (Rounded-off to 2 significant figures)

1100 = 1100 (Rounded-off to 3 significant figures)


1101 = 1110 (Rounded-off to 3 significant figures)
– When rounding off, guard against changing the value of the number to become less than it
was before.

 Truncation Errors
– Truncation is shortening by cutting off some characters abruptly at a certain point.
– For example, 3.9569 truncated to 3 decimal places become 3.956. If truncated to the nearest
whole number, it becomes 3.
– Truncation error is the difference between a truncated value and the actual value. A
truncated quantity is represented by a numeral with a fixed number of allowed digits, with
any excess digits "chopped off" .
– Often, in either floating or fixed point systems, results are calculated with too many places
of accuracy to be represented.
– We get this type of error when trailing bits are truncated to fit the result in the memory
location available.
– Truncation works as follows:

100.1 = 100 (Truncated to 2 significant figures)


10101 = 10000 (Truncated to 2 significant figures)
11011 = 11000 (Truncated to 2 significant figures)
11.101 = 11 (Truncated to 2 significant figures)

45
 Overflow and Underflow
– Since we are working with numbers contained in a fixed number of bits, we must be able
to detect overflow and underflow errors following an operation.
– In signed binary arithmetic, overflow and underflow indicate errors.

a) Overflow
– Overflow occurs when a calculation produces a result that is greater in magnitude than
that which a given register or storage location can store.
– In other words the result is greater than the number of bits available to represent the result
value.
– Overflow occurs when a number is divided by a small number or when two large numbers
are multiplied together.

Detecting Overflow
(i) The sum of two numbers with the sign bits off produces a result number with the sign
bit on.

Example, using 4 bits

4 0100
4 + 0100
-- ------
8 1000 (Overflow has occurred because 8 is out of range)

– Using 4 bits, the range of numbers to be represented is 1000 (-8) to 0111 (+7)

(ii) The sum of two numbers with the sign bits on produces a result number with the sign
bit off.

Example, using 4 bits

8 1000
+ 8 +1000
-- ------
16 10000 (Overflow has occurred because 16 is out of range)
– If you are doing two's complement (signed) arithmetic, overflow occurs when;
(i) Suppose x and y both have sign bits with value 1. That means both represent negative
numbers. If the sum has sign bit 0, then the result of adding two negative numbers has
resulted in a non-negative result, which is clearly wrong.
(ii) Suppose x and y both have sign bits with value 0. That means both represent non-
negative numbers. If the sum has sign bit 1, then the result of adding two non-negative
numbers has resulted in a negative result.

– However, when a negative and a positive number are added together, overflow cannot
occur because the sum is between the two numbers.
– If you are doing two's complement (signed) arithmetic, overflow flag on means the
answer is wrong.
– If you are doing unsigned arithmetic, the overflow flag means nothing and should be
ignored.

46
b) Underflow
– Underflow occurs where the result of a calculation is of very smaller value (close to zero)
than the smallest value that the computer can actually represent in memory.
– Underflow occurs when a small number is divided by a large number or when small
numbers are multiplied together.

Example, using 4 bits

-9 1001
+-7 +0111
---- ------
-16 10000 (Underflow has occurred because -16 (10000) is smaller than -8
(1000) which is the smallest number that can be represented)

– Using 4 bits, the range of numbers to be represented is 1000 (-8) to 0111 (+7)
– The solution to overflow and underflow is to use more bits. Know ahead of time the
minimum and maximum values expected.

Activity 11
Perform a calculation on the following signed binary numbers and indicate whether they
produced an overflow or not:
i) 1000 + 1000
ii) 0100 + 0001
iii) 0110 + 1001
iv) 0000 + 0001
v) 1100 + 1100

 Actual error
– Actual error or absolute error is the difference between the exact/actual value and the
computed value.
– Actual error is obtained by the following formulae:

Actual error =Exact value – Computed value

An exact value is the actual value that is not estimated.


A computed value is the value that is obtained after estimation.

 Relative error
– Relative error is obtained by the following formulae:
Relative error= Actual error/Exact value
Example
2/3 is approximated to 0.666. Find the actual error and relative error.

(i) Actual error

Exact value = 2/3

47
Computed value = 0.666

Actual error = Exact value – Computed value


= 2/3 – 0.666
= 2/3000

(ii) Relative error

Relative error = Actual error/Exact value


= (2/3000) / (2/3)
= 2/3000 x 3/2
= 0.001

Character Set
– A character set refers to all the characters that a computer system can recognise, which
often equates to characters on the keyboard.
– The characters within a character set can be text, number or even symbols.
– Each character is represented by a number, for example, the ASCII character set uses
numbers 0 through 127 to represent all English characters and special symbols.
– The following are examples of character set used by general computers to represent
characters:
 American Standard Code for Information Interchange (ASCII)
 Unicode
 Binary Coded Decimal (BCD)
 Extended Binary Coded Decimal Information Code (EBCDIC)

 American Standard Code for Information Interchange (ASCII)


– ASCII is a way of assigning bit patterns to the characters on the keyboard.
– The ASCII codes are of two types namely ASCII-7 and ASCII-8.
– The ASCII code associates an integer value for each symbol in the character set, such as
letters, digits, punctuation marks, special characters, and control characters.
– ASCII is widely used in computers of all types and communications equipment.
– ASCII codes can just be used for representing characters and not for arithmetic
calculations.

a) ASCII-7
– ASCII-7 is a 7-bit standard ASCII code.
– The first 3 bits are the zone bits and the next 4 bits are for the digits.
– ASCII-7 allows 128 characters to be represented, that is, 27= 128 combinations.

b) ASCII-8
– Manufacturers have added an eight bit to the ASCII-7.
– ASCII-8 allows 256 characters to be represented, that is, 28 = 256 combinations.
– ASCII-8 has 4 bits for zone and 4 bits for the digit.

Table 1: ASCII Character Set

48
49
– Codes 0 to 31and 127 represent non printable control characters.
– Codes 48 to 57 stand for numeric values 0-9.
– Codes 65 to 90 stand for uppercase letters A-Z.
– Codes 97 to 122 stand for lowercase letters a-z.
– Codes 128 to 255 are the extended ASCII codes.
– The space character is the 33rd value, followed by punctuations, digits, uppercase
characters and lowercase characters.
– It is important to note that digit characters have code values that differ from their numeric
equivalents: the code value of '0' is 48, that of '1'is 49, that of '2' is 50, and so forth.
– For example, 32 is the ASCII code for a space. So the binary value for a space is 0100000
(i.e. 32 converted to binary).
– The word Five in ASCII is represented as 006 105 118 101 since 006 represents F, 105
represents i, 118 represents v and 101 represents e. This will translate to 00000110
01101001 01110110 01100101 in binary.
– It is important to note that “120” is treated as 3 characters in ASCII, which is different to
the number 358.

Advantages of using ASCII


– It uses the English language and can hold all the alphanumeric characters
– It uses less space than Unicode because it doesn't have many characters
– It has a "free" bit which can be used for error detection during data transmission.
– Most computers use ASCII codes, which makes it possible to transfer data from one
computer to another.

Disadvantages of using ASCII


– It only makes use of the English language.
– ASCII does not display characters read from a UNICODE document correctly.

 Binary Coded Decimal (BCD)


– BCD is used to represent some numbers that are not proper numbers (numbers that don’t
behave like numbers), for example, barcode.
– BCD is used by digital voltmeters, frequency converters and digital clocks to display output
information in decimal.
– In BCD, each decimal digit is simply changed into a four-bit binary number which are then
placed one after another in order.
– The following shows decimal digits in BCD:

0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

50
– The decimal number 41 is coded as 0100 0001
– The decimal number 9212 is thus coded as 1001 0010 0001 00102 in BCD.

Advantages of using BCD


– It is easy to convert a number from BCD to decimal form and vice versa.
– It is also simple to implement a hardware algorithm for the BCD converter.
– It is useful in digital systems whenever decimal information is given either as input or
displayed as output.

Disadvantages of using BCD


– BCD code for a given decimal number requires more bits than the straight binary code
and hence there is difficult to represent the BCD form in high speed digital computers in
arithmetic operations.
– The speed of the arithmetic operations that can be realised using BCD code is naturally
slow due to the complex hardware circuitry involved.
– The arithmetic operations using BCD code require a complex design of Arithmetic and
Logic Unit (ALU) than the straight binary number system
– The speed of the arithmetic operations that can be realised using BCD code is slow due
to the complex hardware circuitry involved.

For example, adding 1 and 19


(1) 0000 00012
+ (19) 0001 10012
0001 10102

The first digit, 1 is wrong and 1010 does not exist in BCD. The error is caused by the
range of numbers used for representing data in BCD. BCD uses 4 bits which is 2 4 = 16
combinations. However, the maximum range of numbers that can be represented is 9. If
the sum of bit is greater than 9 then 6 has to be added to the result. Thus adding the result
above, 0001 10102 to 6 (0110) gives us 0010 00002, which is 20 in BCD.

 Extended Binary Coded Decimal Interchange Code (EBCDIC)


– The Extended Binary Coded Decimal Interchange Code (EBCDIC) uses 8 bits (4 bits for
zone, 4 bits for digit) to represent a symbol in the data.
– EBCDIC represents 256 characters, that is, 28 = 256 different combinations.
– It represents decimal numbers (0-9), lower case letters (a-z), uppercase letters (A-Z),
Special characters, and Control characters (printable and non-printable e.g. for cursor
movement, printer vertical spacing etc.).
– EBCDIC codes are mainly used in the mainframe and mini computers.

Advantages of using EBCDIC


– An eight-bit code thus having a total of 256 different combinations.
– Code words are all of equal length so relatively easy to decode.

Disadvantages of using EBCDIC

51
– Unlike ASCII there is no "free" bit which can be used for error detection. If a computer
using this code for internal representation is to be connected to a data transmission
system, the data will generally have to be converted to ASCII before transmission.

 Unicode
– Unicode is enough to represent around 120,000 different characters in any language,
English, Chinese and even hieroglyphics.
– Unicode is a universal character encoding standard for the representation of letters,
numbers and symbols.
– Unicode uses 8 bits, 16 bits, 24 bits or 32 bits to represent a character.
– Each character is assigned a unique numeric value that applies across different platforms
and programs.
– The most widely used Unicode encoding schemes are called UTF-8, UTF-16, and UTF-
32.
– UTF-16 is a variable length which uses 16 bits or 32 bits whereas UTF-32 is a fixed
length which uses 32 bits.
– UTF-8 is commonly used and it is a variable length as it contains either 8, 16, 24 or 32
bits for a character.
– UTF-8 characters with a lower Unicode number require fewer bits for their representation
than those with a higher Unicode number.
– Using UTF-8, the character 2 has a decimal value 50 and binary representation of
00110010 whereas the Chinese character is represented by a Unicode number
35987 which translates to 11101000 10110010 10010011 in binary.
– Most Microsoft Software and Linux distributions use Unicode.

Advantages of using UNICODE


– It can store characters from more than one language
– It can store characters from languages with more than 250 characters
– Unicode is almost universally accepted by computing platforms, browsers, and mobile
devices
– Unicode can be used to represent “emojis”. “Emojis” are those little characters such as
a “smiling face with an open mouth”, a “small hand with a thump up” etc. that are used
on Facebook or Whatsapp.

Disadvantages of using UNICODE


– Unicode uses a lot more space than ASCII. It takes 2 bytes to store each character.

Activity 12
1. Represent the following decimal numbers in BCD:
(i) 567
(ii) 21

2. Using the ASCII table, determine the binary equivalence of the following characters:
(i) M
(ii) 7
(iii) &

52
3. Representation the following in ASCII:
(i) Data.
(ii) A byte.

Revision
1. Calculate the number of bytes found in the following:
a) 2 Kilobyte (Kb)
b) 3 Megabyte (Mb)
c) 4 Gigabyte (Gb)
d) 5 Terabyte (Tb) [8]

2. Perform the following binary arithmetic calculations:

a) 1010 / 10

b) 1010 / 11

c) 10.11 / .010

d) 11100 – 1101

e) 111100 + 11101 + 10001

f) 101011 x 110

g) 101.1 x 1.01

h) 111.011 x 0.11 [16]

3. Convert the following decimal values to binary using two’s complement:

a) -92 b) 16 c) 10 d) -123 [8]

4. Round off the following binary numbers to 3 significant figures:

a) 1110 b) 1101 [2]

53
5. Perform the following binary arithmetic and indicate whether an overflow has occurred.

a) 0110 + 0001
b) 0100 + 0001
c) 0111 + 0001
d) 0110 + 1001
e) 1000 + 0001
f) 1100 + 1100 [12]

6. The sum of 2.39 and 1.498 is to be worked using only 3 significant figures.
Find the actual error and relative error if truncation is used. [6]

7. Convert the following denary numbers to (i) octal (ii) hexadecimal

a) 56 b) 78 c)108 [6]

8. Convert the following binary numbers to decimal

a) 1010

b) 11.0001

b) 11.11 [6]

9. Convert the following denary numbers to binary

a) 345
b) 25.575
c) 0.25 [6]

10. a) Using an appropriate number of bytes in each case, express the number 10310 in
(i) binary
(ii) BCD [4]
b) Using the answer obtained in part (a) show how 10310 can be expressed in
(i) octal (ii) hexadecimal with a minimum amount of calculation. [8]

11. a) Outline two advantages of representing numbers in 2s complement


over 1s complement. [2]
b) Assuming that we are working with signed five-bit numbers.
Subtract 001102 from 101112 using the two’s complement representation. [2]
c) Assuming a signed two’s complement representation, find the
decimal value corresponding to 011102 and 101102.. [2]

54
12. a) Using a single byte for each answer, explain how the denary number –29 can be
represented in binary in
(i) sign and magnitude
(iii) 1s complement
(ii) 2s complement [6]
b) (i) Convert -54 and -104 into 2’s complement, 8 bit, binary numbers. [4]
(ii) Add the binary values obtained in b)(i) together. [2]
(iii) Comment on the result that you obtained in b)(ii). [2]

13. Floating-point numbers in a particular computer system are stored using 12 bits. The first 6
bits are used for the storage of the mantissa and the second set of 6 bits is used to store the
exponent.

a) Using the representation above to help you, write the number


(i) 8.5
(ii) -4.5 as a floating-point number in normalised form. [6]
(ii) Explain the effects of changing the representation so that 8 bits are used for the
mantissa and 4 bits for the exponent. [2]

14. The denary number -19¾ is to be represented as a floating point binary number using 12 bits.
The first 8 bits are to be used for the mantissa and the remaining four bits are to be used for
the exponent.
a) Explain what is meant by the mantissa and exponent of a floating point number. [2]
b) Represent the denary number as a normalised floating point binary number. [6]
c) Give the denary number which would have 01000000 111 0 as its binary
floating point representation if 8 bits are used for the mantissa and 4 bits
for the exponent. [4]
d) Explain why it is not possible to represent zero as a normalised floating point number. [2]

15. Using 8 bits for the mantissa and 6 bits for the exponent, normalise the following 2s
complement binary numbers:
a) 110110.112
b) 011111102
c) 0.00010102 [6]

16. Normalise the following floating point binary numbers. The first 8 bits are used for the
Mantissa and the last 4 bits are used for the exponent.
a) 00011101 0110
b) 11000001 1101
c) 11101010 0010 [9]

17. a) Explain the following character sets,


i) ASCII
ii) BCD
iii) Unicode
iv) EBCDIC [8]

b) For the above character sets, state one advantage and one disadvantage of each. [8]

55

You might also like