Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views37 pages

Chapter 1 Data Representation

Uploaded by

mariah jabesi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views37 pages

Chapter 1 Data Representation

Uploaded by

mariah jabesi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Chapter 1 Data Representation

Chapter objectives
Learners should be able to

 Convert from one number base to another

 Addition, subtraction multiplication and division of binary numbers

 Represent binary numbers in ones and twos complement

 Normalize floating point binary numbers

 Change numbers to binary using character sets

 Represent data and character sets

 Distinguish arithmetic errors

Introduction

Data representation refers to the method of encoding and interpreting information in a


computer system. It involves converting real world data into a digital format that can be
processed and stored by a computer. Different types of data, such as numbers, text, images,
audio and video are represented using various encoding schemes. Data representation include
binary representation for numbers, ASCII or Unicode to text and formats like JPEG or PNG for
images. The chosen representation determines how data is stored, transmitted and
manipulated within a computer system.

Number base conversion

Number base conversion refers to the process of changing a number from one numerical
system to another. It involves representing the same value using different base systems such as
decimal (base 10), binary (base 2), octal (base 8), hexadecimal (base 16) or any other base. This
conversion is performed by converting the digit of the number from one base to their
equivalent representation in the desired base
BINARY CONVERSION

Decimal to Binary

To convert decimal number to binary, first divide the decimal by the base noting the reminder
then repeat the process until there is a zero quotient

Example: convert decimal 55 to binary

2 55 R

2 27 1

2 13 1

2 6 1

2 3 0

2 1 1

0 1

The reminder column is read from bottom up

Therefore 55 = 1101112

Conversion from binary to decimal

Firstly, weights (powers of 2) are appended from the right to the left of the binary numbers

Multiple each binary digit with the corresponding weight

Add the values


Example: Converting 110111 to denary

Power 25 24 23 22 21 20

Value 32 16 8 4 2 1

Binary 1 1 0 1 1 1
number

(25 x 1) + (2 x1) + (2 x 0) + (2 x 1) + (2x1) + (2x 1)

(32x1) + (16x1) + (8x0) + (4x1) + (2x1) + (1x1)

32 + 16 + 8 + 4 + 2 + 1

Therefore 1101112 = 55

Conversion of Binary fraction to decimal

Example: converting 1011.011

Powers 2 2 2 2 . 2 2 2

Value 8 4 2 1 0.5 0.25 0.125

Binary number 1 0 1 1 . 0 1 1

Multiple the values and add them.

(2x1)+ (2x0) + (2x1) + (2x1). (2x0)+ (2x1) + (2x1)

(8x1)+(4x0)+(2x1)+(1x1) .(0.5x0)+(0.25x1)+(0.125x1)

8 + 0 + 2 + 1.0 + 0.25 + 0.125

Therefore 1011.0112 = 11.375


Conversion of decimal fraction to binary

Example: converting 15.75

First stage is converting decimal 15 to binary

2 15 R

2 7 1

2 3 1

2 1 1

0 1

Hence 15 = 11112

Second stage is to convert the decimal fraction 0.75

Multiple 0.75 x 2 = 1.5, so the value 1 becomes the first digit after the binary point. Repeat the
multiplication of the fractional part until it become 0.

0.75 x2 1.5 1 becomes the first digit after the binary point

0.5 x 2 1.0 1 becomes the second digit after the binary point

NB the fractional part becomes 0, so multiplication ends.

The decimal and decimal fraction conversions to binary are combined

15 = 1111

0.75 = 11

Therefore 15.75 = 1111.112

Task

1. Convert the following decimal (denary) to binary


a) 78 b) 304 c) 43.125
2. Convert binary to decimal (denary)
a) 11012 b) 011010002 c) 1100.1101

OCTAL CONVERSION

Conversion from decimal to octal

Example: converting denary 121 to octal

8 121 R

8 15 1

8 1 7

0 1

Therefore 121 = 1718

Example: converting octal number 345 to decimal

Power 82 81 80

Value 64 8 1

Octal number 3 4 5

(82 x 3) + (81 x 4) + (80 x 5)

(64 x 3) + (8 x 4) + (1 x 5)

192 + 32 + 5

= 229

Therefore 3458 = 229

Conversion of octal fraction to decimal


Example: Converting 127.31 to decimal

Powers 82 81 80 . 8-1 8-2

Value 64 8 1 . 0.125 0.015625

Octal number 1 2 7 . 3 1

Multiple the values and add them.

(82 x 1) + (81 x2) + (80 x7) + (8-1 x3) + (8-2 x1)

(64 x 1)+(8x2)+(1 x 7) + (0.125x3)+(0.015625x1)

64 + 16 + 7 + 0.375 + 0.015625

Therefore 127.318 = 87.390625

Conversion of decimal fraction to octal

Example: converting 35.15 to octal

First stage is converting decimal 35 to binary

8 35 R

8 4 3

8 0 4

Second stage is to convert the decimal fraction 0.15

Multiple 0.15 x 8 = 1.2, so the value 1 becomes the first digit after the binary point. Repeat the
multiplication of the fractional part until it become 0.

0.15 x 8 1.2 1 becomes the first digit after the binary point

0.2 x 8 1.6 1 becomes the second digit after the binary point

0.6 x 8 4.8 4 becomes the third digit after the binary point
0.8 x 8 6.4 6 becomes the fourth digit after the binary point

0.4 x 8 3.2 3 becomes the fifth digit after the binary point

0.2x 8 1.6 1 becomes the sixth digit after the binary point

0.6 x 8 4.8 4 becomes the seventh digit after the binary point

0.8 x 8 6.4 6 becomes the eighth digit after the binary point

The fractional part becomes 0. 1463146, hence it becomes an infinite fractions with a repeating
pattern on 0.1463146…… digits.

The decimal and decimal fraction conversions to octal are combined

35 = 438

0.15 = 11463

Therefore 35.15 = 43.114638

Task
1. Convert the following decimal (denary) to octal
a) 54 b) 459 c) 130. 75
2. Convert octal to decimal (denary)

a) 478 b) 3228 c) 31.258

HEXADECIMAL CONVERSION

Conversion from decimal to hexadecimal

Example: converting denary 13 to hexadecimal

16 93 R

16 5 13
0 5

Therefore 93 = 5D16

Example: converting denary 393 to hexadecimal

16 393 R

16 24 9

16 1 8

0 1

Therefore 393 = 18916

Conversion from hexadecimal to decimal

Example: converting 23F to decimal

Power 162 161 160

Value 256 16 1

Hexadecimal 2 3 F

(16x2)+ (16x3) + (16xF)

(256x2)+ (16x3) + (1x15)

512 + 48 + 15

Therefore 23F16 = 575

Conversion of hexadecimal fraction to decimal

Example: Converting C2B.12 to decimal

Powers 162 161 160 . 16-1 16-2

Value 256 16 1 . 0.0625 0.00390625


hexadecimal C 2 B . 1 2
number

Multiple the values and add them.

(162 x C) + (161 x2) + (160 x B) + (16-1 x1) + (16-2 x2)

(256 x 12) + (16 x 2) + (1 x 11) + (0.0625 x 1) + (0.00390625 x 2)

3072 + 32 + 11 + 0.0625 + 0.0078125

Therefore C2B.128 = 3115.0703125

Conversion of decimal fraction to hexadecimal

Example: Converting 299.25 to hexadecimal

First stage is converting decimal 299 to hexadecimal

16 299 R

16 18 11

16 1 2

16 0 1

Second stage is to convert the decimal fraction 0.25

Multiple 0.25 x 16 = 4.0, so the value 1 becomes the first digit after the binary point. Repeat the
multiplication of the fractional part until it become 0.

0.25 x 16 4.0 4 becomes the first digit after the binary point

The decimal and decimal fraction conversions to hexadecimal are combined


299 = 12B16

0.25 = 0.4

Therefore 299.25 = 12B.416

Task

1. Convert the following decimal (denary) to hexadecimal


a) 51 b) 312 c) 64. 75
2. Convert hexadecimal to decimal (denary)
a) 2E16 b) 43B16 c) 2C.2516

Octal conversion to binary and vice versa

Binary 000 001 010 011 100 101 110 111

Octal 0 1 2 3 4 5 6 7

To convert binary number to octal, group the binary digits into groups of three starting from
the right most digit. If the last group to the left is less than three digits add zeros.

Conversion from binary to octal

Example: Convert 11101012 to octal

Binary 001 110 101

Octal 1 6 5

Therefore 11101012 = 1658


Conversion from octal to binary

Converting from octal to binary, the groups of three binary digits corresponding to each octal
digit is written.

Example: converting 47138 to binary

Octal 4 7 1 3

Binary 100 111 001 011

Therefore 47138 = 1001110010112

Hexadecimal conversion to binary and vice versa

Binary 0000 0001 0010 0011 0100 0101 0110 0111

Hexadecimal 0 1 2 3 4 5 6 7

Binary 1000 1001 1010 1011 1100 1101 1110 1101

Hexadecimal 8 9 A B C D E F

Conversion from binary to hexadecimal

Example: convert 01100111112 to hexadecimal

Binary 0001 1001 1111

Hexadecimal 1 9 F

Therefore 01100111112 = 19F16

Conversion from hexadecimal to binary

Example: convert 5EB716 to binary

Hexadecimal 5 E B 7

Binary 0101 1110 1011 0111

Therefore 5EB716 = 01011110101101112


Task

1. Convert the following from binary to octal


a) 10012 b) 011100116
2. Convert the following from octal to binary
a) 5558 b) 26348
3. Convert the following from binary to hexadecimal
a) 10111112 b) 11101.0112
4. Convert the following from hexadecimal to binary
a) 6F16 b) 1BE16
Binary system
It is a number system that uses only two digits 0 and 1. It is a fundamental system in digital
computing and information storage because it is compatible with binary nature of electronic
device. In the binary system, each digit is called a bit which is short for binary digit. These bits
are used to represent information and perform arithmetic operations

Binary arithmetic

Addition

1 1 1 1 1 (carry)

1 0 1 1 1 1 1

+ 1 1 0 1 0 1 0

1 1 0 0 1 0 0 1

Subtraction

1 0 0 1

- 0 1 1 0

0 1 1 1

Multiplication

Example 1

1 0 1 1

x 1 0 1

1 0 1 1 0 0

+ 1 0 1 1

1 1 0 1 1 1
Example 2

1 1 0 1 1 . 1

x 1 . 0 1

1 1 0 1 1 1 0 0

+ 1 1 0 1 1 1

1 0 0 0 1 0 . 0 1 1

Division

Example 1

1 0 1 R 1 0 0

1 0 1 1 1 1 0 1

- 1 0 1

1 0 0 1

- 1 0 1

1 0 0

Example 2

1 1 0 1

1 0 1 1 0 . 1 1

1 0

1 0
1 0

0 1 1

1 0

Octal arithmetic

Addition

Example: 528 + 68

5 2

+ 6

6 08

Example: 3718 + 1458

1 (carry)

3 7 18

+ 1 4 58

5 3 68

Subtraction

Example: 4578 - 2648

4 5 78

- 2 6 48

1 7 38
Multiplication

Example : 178 x 28

1 (carry)

1 78

x 28

3 68

Hexadecimal arithmetic

Addition

Example: 9AC16 + 16F16

9 A C16

+ 1 6 F16

B 1 B16

Subtraction

Example: BA616 – C316

B A 616

_ C 316

A E 316
Multiplication

Example: 5B16 x 3A16


2 (Carry)

5 B16

x 3 A16

1 1 1 016

+ D E16

1 1 E E16

Division

Example: 544916 / C16

4 5 4 R 1

C 5 4 4 9

- 4 8

6 4

- 6 0

4 9

- 4 8

1
Ones complement

One’s complement is a method of representing signed binary numbers by inverting or


complementing all the bits of the binary number. The sign bit, which is the most significant bit
(MSB), is 0 for positive numbers and 1 for negative numbers. The magnitude bits, which are the
remaining bits, are the same as the unsigned binary number for positive numbers, and the
inverted or complemented bits of the unsigned binary number for negative numbers.

Example: using 4 bits to represent 3 in one’s complement


Steps to follow
Convert 3 to binary = 011
Add 1 zero to the left most digit to make the 4 bits = 0011
Therefore +3= 0011

For a positive number the binary remains the same


The one’s complement of +3 (0011) = 0011

Example: using 4 bits to represent -3 in one’s complement


Steps to follow
Convert 3 to binary = 011
Add 1 zero to the left most digit to make the 4 bits = 0011
+3= 0011
For a negative number we negate the binary
The one’s complement of -3(0011) = 1100
Therefore -3= 1100

In one's complement representation, the range that can be represented is divided into two
parts: positive values and negative values. Let's assume we are working with a 4-bit one's
complement representation for simplicity.

Positive Values: In a 4-bit one's complement representation, positive values are represented
directly without any special encoding. The range of positive values can be calculated using the
formula 2^ (n-1) - 1, where n represents the number of bits. For example, in a 4-bit one's
complement representation, the formula gives us ((2^3) - 1) = 7. Therefore, the positive values
that can be represented in this 4-bit one's complement format range from 0 to +7.
Negative Values: In one's complement representation, negative values are formed by taking the
one's complement of the corresponding positive value and adding a sign bit to the MSB
position. Using our example of a 4-bit representation, the negative values can be calculated
using the formula - ((2^ (n-1)) - 1). For a 4-bit one's complement representation: Negative range
= - ((2^3) - 1) = -7. Therefore, the negative values that can be represented in this 4-bit one's
complement format range from -7 to -1.

One’s complement has some advantages and disadvantages, such as: It is easy to obtain the
one’s complement of a binary number by simply flipping all the bits. It allows subtraction to be
performed by adding the one’s complement of the subtrahend to the minuend. It has two
representations for zero: +0 (00000000) and -0 (11111111), which can cause confusion and
inconsistency.

Addition

Using 4 bits add 6 and 2


1 1 (carry)

6 0 1 1 0

+ 2 + 0 0 1 0

8 1 0 0 0

Using 8 bits add 10 and -3

First convert -3 to 8 bits equivalent (00000011) then negate to (11111100)


1 1 1 1 1

1 0 0 0 0 0 1 0 1 0

+ -3 1 1 1 1 1 1 0 0

[1] 0 0 0 0 0 1 1 0

7 0 0 0 0 0 1 1 1

NB: The carry out [1] is add back to 00000110 resulting in 00000111, the result is 7 in decimal.
Subtraction

Using 4 bits subtract 9 and 5 using one’s complement

First convert 5 to 4 bits equivalent (0101) then negate to (1010)

1 1 1

9 1 0 0 1

- 5 + 1 0 1 0

[1 0 0 1 1
]

+ 1

4 0 1 0 0

NB: The carry out [1] is add back to 0011 resulting in 0100 2, the result is 4 in decimal.

Two’s complement

It is a method of representing signed binary numbers by adding 1 to the one’s complement of


the binary number. The sign bit, which is the most significant bit (MSB), is 0 for positive
numbers and 1 for negative numbers. The magnitude bits, which are the remaining bits, are the
same as the unsigned binary number for positive numbers, and the one’s complement plus 1 of
the unsigned binary number for negative numbers.

Example: Using 8 bits to represent +6 in two’s complement


Steps to follow
Convert 6 to binary = 110
Add 5 zeros to the left most digit to make the 8 bits = 00000110
Therefore +6 = 00000110
Example: using 8 bits to represent -6 in two’s complement
Steps to follow
Convert 6 to binary = 110
Add 5 zeros to the left most digit to make them 8 bits = 00000110
We negate 00000110 to 11111001

11111001 (one’s complement)


+ 1 (add 1)
11111010 (two’s complement)
Therefore -6 = 111110102

Two’s complement has some advantages and disadvantages, such as: It is easy to obtain the
two’s complement of a binary number by finding the one’s complement and adding 1, or by
starting from the least significant bit and copying all the bits until the first 1, then flipping the
remaining bits. Two’s complement allows subtraction to be performed by adding the two’s
complement of the subtrahend to the minuend, without any end-around carry. It has only one
representation for zero: 00000000, which eliminates the ambiguity and inconsistency of one’s
complement.

Addition using two’s complement

In two’s complement representation, addition involves performing binary addition just like in
regular binary arithmetic. The difference lies in how negative numbers are represented. The
most significant bit (MSB) is used indicate the sign of a number

To add two number in two’s complement, the steps are as follows:

 Align the binary numbers, ensuring that they have the same number of bits. If they do
not have, pad zeros to the left of the shorter number.

 Start with the right most bits of the numbers and perform regular binary addition. Add
the corresponding bits together include the carry if there is any.

 If there is a carry out from the left most bit of the addition it indicates an overflow.
Ignore this carry as it falls of the end.

 Note that in two’s complement, a positive number has a 0 MSB, while a negative
number has a 1 MSB. The MSB of the result will carry the sign information.
 If the result’s MSB is 1, it means the sum is negative. Convert the result from two’s
complement back to its decimal representation if needed.

It is important to remember that in two’s complement, the range of representable is defined by


the number of bits used. For example, with 8 bits, the range is -128 to 127. Overflow occurs
when the result of addition falls outside this range.

Example: Addition of positive numbers

Using 4 bits add 7 and 5 in two’s complement


1 1

7 0 1 1 1

+ 5 0 1 0 1

1 2 1 1 0 0

Example: Addition of positive number with a negative number

Using a 6 bit add 21 and -6

First convert -6 to 6 bits equivalent (000110) then negate (flip) to 111001 + 1 = 111010

Add 111010 to 010101


1 1

2 1 0 1 0 1 0 1

+ -6 1 1 1 0 1 0

1 5 [1] 0 0 1 1 1 1

Therefore discard carry out [1], the result is 0011112 (15)

Subtraction using two’s complement

It is a method used to perform arithmetic subtraction in binary representation. It allows


subtraction operations to be performed using only addition operations, utilizing the concept of
complementing numbers.
To subtract one binary number from another using two’s complement, the following steps are
followed:

 Represent the numbers in binary: Convert the numbers to their binary representation if
they are not already in binary form.

 Determine the complement of the number being subtracted: To find the complement of
a binary number, invert (flip) all the bits to their opposite values. For example to find the
complement 1101, we change all the 0s to 1s and vice versa, resulting in 0010

 Add the complement to the original number: Perform binary addition by adding the
original number and the complement together, just like regular addition.

 Ignore any carry out from the most significant bit (leftmost bit), as it is discarded in
two’s complement arithmetic.

 Interpret the result: If there is a positive carry out (overflow) after adding, it means the
result is negative otherwise the result is positive or zero, depending on the bits
obtained.

Example

Using 4 bits Subtract 9 from 13

First convert 9 to 4 bits equivalent (1001) then negate (flip) to 0110 + 1 = 0111

Add 1101 (13) to 0111


1 1 1

1 3 1 1 0 1

- 9 + 0 1 1 1

4 [1] 0 1 0 0

Therefore discard carry out [1], the result is 01002 (4)

Represent the number in binary

Floating point arithmetic


Floating point arithmetic is a way of performing calculations with real numbers using a
computer system. Real numbers are numbers that can have fractional or decimal parts, such as
3.14, -0.5, or 6.022e23. Floating point arithmetic allows the computer to represent and
manipulate these numbers using binary digits.

The term floating point refers to the fact that the decimal point (or binary point) of the number
can be placed anywhere relative to the significant digits of the number. This position is
indicated by an exponent, which is another number that specifies how many places the decimal
point should be moved. For example, the number 123 can be also be represented as 1.23 x
10^2 by moving the decimal point two places to the left.

A floating point number consists of three parts: a sign bit, a significant, and an exponent. The
sign bit is a single bit that indicates whether the number is positive or negative. The significant
is a sequence of bits that represents the magnitude or value of the number. The exponent is
another sequence of bits that represents the power of the base (usually 2) that the significant
should be multiplied by.

For example, using 8 bits, the number -5.25 can be represented as 1 0101001 001, where 1 is
the sign bit, 0101001 is the significant, and 001 is the exponent.

There are different formats and standards for floating point arithmetic, depending on the
number of bits used and the rules for rounding, overflow, underflow, and special values. The
most common standard is the IEEE 754 can represent numbers typically ranging from
approximately 1.17549e-38 to 3.40282e+38, which defines several formats for different
precisions and ranges of numbers. For example, the single-precision format uses 32 bits, with 1
bit for the sign, 8 bits for the exponent, and 23 bits for the significant.

Floating point arithmetic advantages and applications.

It can represent a wide range of numbers, from very large to very small, with a fixed number of
bits. Floating point can perform calculations with real numbers that are not possible or
convenient with integer arithmetic, such as fractions, decimals, roots, powers, logarithms,
trigonometry, etc. It can be used for scientific, engineering and mathematical computation hat
require high accuracy and precision.
Floating point arithmetic limitations

It cannot represent every real number exactly, due to the finite number of bits and the
rounding errors that may occur. For example, the decimal number 0.1 cannot be represented
exactly as a binary fraction, so it is approximated by the nearest binary fraction that can fit in
the available bits. This causes a small error in the representation, which may propagate and
accumulate in subsequent calculations.

It may produce unexpected or incorrect results, due to the limitations of the format and the
standard. For example, some operations may result in overflow, underflow, or NaN (not a
number), which are special values that indicate an invalid or undefined result.

Normalisation of floating point numbers

Normalization is a process that is used to convert a floating point number into a standardized
format. The standard format for floating point numbers is known as the IEEE 754 standard. This
standard defines a format for floating point numbers that includes the sign, exponent, and
mantissa. The sign indicates whether the number is positive or negative. The exponent
indicates how many places the decimal point is shifted. The mantissa is the actual value of the
number. By converting a floating point number to the IEEE 754 standard format, we can ensure
that the number is represented accurately.

Advantages of normalisation

There are several advantages to normalizing floating point numbers. First, it helps to prevent
round-off errors, since all numbers are represented in the same standardized format. Second, it
makes it easier to compare numbers, since they are all represented in the same way. Third, it
makes it easier to perform arithmetic operations on numbers, since they are all in the same
format. Finally, it helps to conserve memory, since all numbers are stored in the same format.

Mantissa and exponent

Mantissa and exponent are two terms that are used to describe the parts of a number that is
written in scientific notation or floating point representation. Scientific notation and floating
point representation are ways of expressing number that are too large or too small to be
written in the normal decimal form.
Scientific notation is a way of writing numbers using a base (usually 10) and an exponent. The
number is written as a product of a mantissa and a power of the base. The mantissa is a decimal
number between 1 and 10, and the exponent is an integer that indicates how many places the
decimal point should be moved.

For example, the number 5367 can be written in scientific notation as 5.367 x 10^3, where
5.367 is the mantissa and 3 is the exponent.
 Identify the mantissa: The mantissa represents the significant digits of the number,
ignoring any leading or trailing zeros. In this case, the mantissa is 5367.
 Determine the exponent: the exponent is the power or ten by which the mantissa
should be multiplied or divided to represent the original number. We can find the
exponent by counting the number of places we need to move the decimal point to reach
the original number. In this case, we need to move the decimal point 3 places to the left.
Therefor the exponent is -3.
 Normalize the mantissa: To normalise the mantissa, we adjust its value so that it is
between 1 and 10. In this case the mantissa 5.367 is within the range.
 Represent the number in scientific notation: Using the mantissa and exponent we can
express the original number in scientific notation. This case the normalise form is
5.367 x 10^3.
 The normalised representation of the number 5367 is 5.367 x 10^3.

Floating point representation

It is a way of writing numbers using a binary base (2) and an exponent. The number is written as
a product of a sign bit, a significant, and a power of the base. The sign bit is a single bit that
indicates whether the number is positive or negative. The significant is a binary fraction
between 0.5 and 1, and the exponent is an integer that indicates how many places the binary
point should be moved. For example, the number-5.25 can be written in floating point
representation as 1.010101 x 2^2, where 1 is the sign bit, 0.010101 is the significant, and 2 is
the exponent.

The mantissa and the exponent are different ways of representing the magnitude and the scale
of a number. They can help simplify the calculations and the storage of numbers that are very
large or very small.

Fixed point arithmetic


Fixed point arithmetic is a way of performing calculations with real numbers using a computer
system. Real numbers are numbers that can have fractional or decimal parts, such as 3.14, -0.5,
or 6.022e23. In fixed point binary number system, numbers are represented using a fixed
number of bits to represent the integer part and a fixed number of bits to represent the
fractional part. For example, in a system with 4 bits, the integer part would be represented
using the first 2 bits, and the fractional part would be represented using the last 2 bits.

A fixed point number consists of two parts: a sign bit and a magnitude. The sign bit is a single
bit that indicates whether the number is positive or negative. The magnitude is a sequence of
bits that represents the value or size of the number.

Types of fixed point arithmetic

 Q format: It is a standard notation for fixed point arithmetic that specifies the number of
integer bits and fractional bits in the magnitude. For example, Q7.8 means that the
magnitude has 7 integer bits and 8 fractional bits, and the sign bit is not counted.
 Binary scaling: It is a method of fixed point arithmetic that uses a power of 2 as the
scaling factor. For example, the value 1.23 can be represented as 10011010 with a
scaling factor of 2^-2, meaning that the binary point is 2 places to the left of the least
significant bit.
 Decimal scaling: It is a method of fixed point arithmetic that uses a power of 10 as the
scaling factor. For example, the value 1.23 can be represented as 10011010 with a
scaling factor of 10^-2, meaning that the decimal point is 2 places to the left of the least
significant bit.

The advantages of fixed point arithmetic are that they are accurate, has a high precision and are
easy to convert between decimal and binary representation. However their disadvantages are
that they are not as efficient as floating point arithmetic and they can only represent a limited
range of values.

Range of numbers that can be represented

The range of numbers that can be represented in a fixed point system is determined by the
number of bits used to represent the integer part and the fractional part. For example, in a
system with 8 bits, the integer part would be represented using 4 bits, and the fractional part
would be represented using 4 bits. This means that the range of numbers that can be
represented in this system is from -8 to +7, with a precision of 0.5. The range of numbers that
can be represented in a floating point system is determined by the number of bits used to
represent the exponent and the mantissa.
Fixed point fractional binary numbers

In a fixed point fractional binary number system, the maximum positive number is equal to 1
less than the number of bits used to represent the fractional part. For example, in a system
with 4 bits, the maximum positive number would be 3. The minimum positive number is 1 less
than the maximum negative number. This means that in a system with 4 bits, the minimum
positive number would be -2. The range of numbers that can be represented is from -2 to +3,
with a precision of 0.25.

Integer representation

In sign and magnitude representation, a sign bit is used to indicate whether a number is
positive or negative. The sign bit is usually the leftmost bit. If the sign bit is 1, the number is
negative, and if it is 0, the number is positive. The remaining bits are used to represent the
magnitude of the number. For example, in a system with 4 bits, the number 1011 would be
represented as -3. The sign bit (1) indicates that the number is negative, and the remaining 3
bits (011) represent the magnitude of the number (3).

Computer arithmetic errors

Computer arithmetic errors are errors that occur when a computer performs calculations with
numbers that are not represented exactly in its system. These errors can affect the accuracy
and reliability of the results, and may cause unexpected or undesired outcomes.

Types of arithmetic errors

Overflow error occur when a number is too large to be represented in the computer's memory,
resulting in an incorrect result. All three types of errors can lead to inaccurate results, which can
cause problems in calculations.

Underflow error occurs when a number is so small that it becomes zero or a very small number
when it is rounded or truncated. For example, if a number is 0.0001 and it is rounded to the
nearest integer, it becomes zero. This can cause problems in calculations, since the actual value
of the number is not zero. Underflow errors can be detected by checking for values that are
very close to zero.

Round-off errors are errors that occur when a number is approximated by a finite number of
digits or bits. For example, the decimal number 0.1 cannot be represented exactly as a binary
fraction, so it is rounded to the nearest binary fraction that can fit in the available bits. This
causes a small error in the representation, which may propagate and accumulate in subsequent
calculations. Rounding errors occur when a number is rounded to the nearest value, resulting in
a loss of precision.

Truncation errors are errors that occur when an infinite or very large process is approximated
by a finite or smaller one. For example, the value of pi cannot be computed exactly by any
algorithm, so it is truncated to a finite number of digits or bits. This causes a small error in the
approximation, which may affect the accuracy of the calculations that use it. Truncation errors
occur when a number is truncated, or cut off, resulting in the loss of a digit.

Actual error, also known as absolute error, is the difference between the computed or
measured value and the true or exact value. It is expressed with the same units as the values.
For example, if the true value of a length is 10 cm and the measured value is 9.8 cm, the actual
error is 0.2 cm. Actual error indicates how much the computed or measured value deviates
from the true value, but it does not take into account the magnitude or scale of the values.

Relative error, also known as fractional error or relative deviation, is the ratio of the actual
error to the true or exact value. It is expressed as a fraction or a percentage. For example, if the
true value of a length is 10 cm and the measured value is 9.8 cm, the relative error is 0.2 / 10 =
0.02 or 2%. Relative error indicates how large the actual error is compare to the true value, but
it does not show the actual amount of error.

Both actual error and relative error are important for assessing the quality and reliability of
numerical methods and calculations. They can help identify the sources and effects of errors,
such as rounding, truncation, measurement, and approximation errors.

Character sets
A character set is a collection of characters that are used to represent text in a computer
system or a document. A character is a minimal unit of text that has a meaning, such as a letter,
a digit, a symbol, or a punctuation mark.

American Standard Code for Information Interchange (ASCII)

It is a character encoding standard that assigns a numerical value to each character, such as
letters, digits, punctuation marks, and some special symbols. ASCII uses 7 bits to represent each
character, which means it can encode up to 128 different characters. The first 32 characters (0-
31) are control codes that are used to control devices such as printers and terminals. The next
95 characters (32-126) are printable characters that can be displayed on the screen.
ASCII was developed in the early 1960s as a standard way of exchanging information between
computers and electronic devices. It was based on earlier telegraph codes and was designed to
be easy to sort and use.

advantages of ASCII include its simplicity and its wide adoption.

Some disadvantages of ASCII include its limited character set and the fact that it cannot
represent all languages

Binary coded decimal (BCD)

It is a way of representing decimal numbers using binary digits. Each decimal digit (0 to 9) is
encoded as a four-bit binary number, and then the binary numbers are concatenated to form
the BCD code.

BCD is different from simple binary representation, where the whole decimal number is
converted into a single binary number by dividing by 2 repeatedly. For example, the decimal
number 42 is encoded as 101010 in simple binary representation. BCD uses more bits to
represent the same decimal number than simple binary representation, but it has some
advantages, such as:

It is easier to convert between BCD and decimal than between simple binary and decimal,
because each digit is encoded separately.

It avoids rounding errors and loss of precision that may occur in floating-point representation,
especially for fractional numbers.

There are different types of BCD, such as packed BCD and unpacked BCD, depending on how
the binary digits are stored and processed. Packed BCD stores two BCD digits in one byte, while
unpacked BCD stores one BCD digit in one byte.

Binary coded decimal (BCD) is a method of representing decimal numbers using binary digits.
Each decimal digit is represented by a 4-bit binary number.

Advantages of BCD

The main advantage of BCD is that it is easy to understand and use, since it is based on the
decimal system. BCD also has a relatively small memory footprint, since it only requires 4 bits
per decimal digit.

Disadvantages of BCD

However, BCD has a few disadvantages as well. One of the main disadvantages of BCD is that it
is less efficient than other methods of representing decimal numbers, such as UNICODE or
floating point numbers. Additionally, BCD does not support negative numbers. Finally, BCD is
not as widely supported as other character sets, such as UNICODE.

Unicode
UNICODE is a 16-bit character set that was developed to replace ASCII. It is designed to support
all of the world's languages, including those that use non-Latin alphabets. It also includes a wide
range of special characters, such as mathematical symbols and emoji.

Some advantages of UNICODE include its large character set and its ability to represent all
languages.

Some disadvantages of UNICODE include its complexity and the fact that it requires more
memory than ASCII.

Unicode is a standard for character encoding that aims to support the text of all the world’s
writing systems. It assigns a unique number, called a code point, to each character, such as
letters, digits, punctuation marks, and symbols.

Unicode has several advantages over other character encoding standards, such as ASCII and
ISO/IEC 8859.

Some of these advantages are:

 It can represent characters from many languages and scripts in a single document or file.
 It can avoid data loss or corruption due to incompatible encodings or conversions.
 It can simplify the development and maintenance of software and systems that handle
multilingual text.
 It can facilitate the exchange and interoperability of data across different platforms and
applications.

Unicode uses different formats to store and transmit the code points as binary data. These
formats are called Unicode Transformation Formats (UTFs). The most common UTFs are:

UTF-8: It uses one to four bytes to encode each code point. It is compatible with ASCII and
widely used on the Internet and in web development.

UTF-16: It uses two or four bytes to encode each code point. It is commonly used in Windows
and Java environments.

UTF-32: It uses four bytes to encode each code point. Here are some examples of how Unicode
encodes some characters in different UTFs:
Character Code point UTF-8 UTF-16 UTF-32

A U+0041 41 0041 00000041

€ U+20AC E2 82 AC 20AC 000020AC

你 U+4F60 E4 BD A0 4F60 00004F60

😊 U+1F60A F0 9F 98 8A D83D DE0A 0001F60A

Extended Binary Coded Decimal Interchange Code (EBCDIC)

This is an 8-bit character encoding system developed by IBM in the early 1960s. It was created
as an extension of the Binary Coded Decimal (BCD) encoding that existed at the time. EBCDIC is
primarily used on IBM mainframe and midrange computer operating systems.

EBCDIC was devised as a way to encode characters for use in IBM’s range of mainframe
computers, starting with the System/360 line. It was designed before the widespread adoption
of ASCII (American Standard Code for Information Interchange) and was intended to be an
efficient means of encoding data for storage and processing on IBM systems.

EBCDIC uses eight binary bits to represent each character, allowing it to encode a total of 256
different characters. This includes letters, numbers, punctuation marks, and control characters.
The encoding scheme assigns a unique binary number to each character, which can be
represented as two hexadecimal digits.
One of the key differences between EBCDIC and ASCII is the arrangement and assignment of
binary values to characters. For example, the capital letter ‘A’ is represented as x'C1' in EBCDIC
and x'41' in ASCII. This difference in encoding means that when data is transferred between
systems using different character sets, conversion is necessary to maintain the integrity of the
information.

The collating sequence, or the order in which characters are sorted, differs between EBCDIC
and ASCII. In EBCDIC, the general order from lowest to highest value is space, punctuation,
numbers, uppercase letters, and lowercase letters. In contrast, ASCII’s sequence is space,
punctuation, uppercase letters, lowercase letters, and then numbers. This affects how strings
are sorted and processed in programs.

Summary
Data representation is crucial for ensuring accurate storage, processing and exchange of
information into computer system. It forms the foundation of computer science and enables
the development of efficient algorithms and software applications.Character sets includes
ASCII, Unicode, BCD and EDCDIC. These are different from character encoding, which is a
method of mapping the characters to binary data. Character encoding can affect how the
characters are displayed, stored, and transmitted by computer systems. Some character sets
have only one encoding, while others have multiple encodings.
End of chapter questions
1. What is the result of adding the binary numbers 10101 and 1101?

2. Subtract the binary number 10010 from 1101

3. Multiply the binary number 1010 and 1.10

4. Divide the binary number 101110 by 101

5. Find the two’s complement of the binary number 01101 and 101001

6. What is sign and magnitude representation?

7. What is the difference between a denormalised and normalised floating point number?

8. Why is normalization of a floating point number important?

9. Discuss the significance of precision error in computer arithmetic.

10. Explain the concept of overflow error in computer arithmetic and provide an example.

11. What is underflow error and how does it affect arithmetic operations

12. What is a character set in computer systems and why is it important

13. Explain the difference between the following character sets

a) ASCII and Unicode

b) BCD and EBCDIC

14 Real number are stored in floating representation with

8 bit for the mantissa followed by

4 bit for the exponent

Two's complement used for both the mantissa and the exponent

Consider 11011011 0110

Calculate this binary to denary

You might also like