1.data Representation A Level
1.data Representation A Level
REPRESENTATION
CONTENT TO BE COVERED IN FORM 5
ONLY.
TOPICS TO BE COVERED DURING THE
COURSE:
I. NUMBER BASES
II. FLOATING POINT ARITHMETIC
III. COMPUTER ARITHMETIC
ERRORS
IV. DATA REPRESENTATION
I. NUMBER BASES
- Binary
- Octal
- Denary
- Hexadecimal
- 2s Compliment
BITS AND BINARY
Computers use binary - the digits 0 and 1 - to store
data. A binary digit, or bit, is the smallest unit of data
in computing. It is represented by a 0 or a 1. Binary
numbers are made up of binary digits (bits), e.g. the
binary number 1001.
The circuits in a computer's processor are made up of
billions of transistors. A transistor is a tiny switch that
is activated by the electronic signals it receives. The
digits 1 and 0 used in binary reflect the on and off
states of a transistor.
ENCODING
Everything on a computer is represented as streams
of binary numbers.
Audio, images and characters all look like binary
numbers in machine code. These numbers are
encoded in different data formats to give them
meaning, e.g. the 8-bit pattern 01000001 could be the
number 65, the character 'A', or a color in an image.
Encoding formats have been standardized to help
compatibility across different platforms. For example:
audio is encoded as audio file formats, e.g. mp3, WAV,
AAC
video is encoded as video file formats, e.g. MPEG4,
H264
text is encoded in character sets, e.g. ASCII, Unicode
images are encoded as file formats, e.g. BMP, JPEG,
PNG
BINARY AND DENARY
The binary system on computers uses combinations of 0s and 1s.
In everyday life, we use numbers based on combinations of the digits
between 0 and 9. This counting system is known as decimal, denary or
base 10.
A number base indicates how many digits are available within a
numerical system. Denary is known as base 10 because there are ten
choices of digits between 0 and 9. For binary numbers there are only
two possible digits available: 0 or 1. The binary system is also known
as base 2.
All denary numbers have a binary equivalent and it is possible to convert
between denary and binary.
1.PLACE VALUES DENARY PLACE
VALUES
Using the denary system, 6432 reads as six
thousand, four hundred and thirty two. One
way to break it down is as:
six thousands
four hundreds
three tens
two ones/units
Each number has a place value which could be put into columns. Each
column is a power of ten in the base 10 system:
Or think of it as:
(6 x 1000) + (4 x 100) + (3 x 10) + (2 x 1) = 6432
BINARY PLACE VALUES
You can also break a binary number down into place-value
columns, but each column is a power of two instead of a
power of ten.
For example, take a binary number like 1001. The
columns are arranged in multiples of 2 with the binary
number written below:
By looking at the place values, we can calculate the equivalent
denary number.
That is: (1 x 23) + (0 x 22) + (0 x21) + (1x20) = 8+0+0+1
(1 x 8) + (0 x 4) + (0 x 2) + (1 x 1) = 8 + 1 = 9
Binary arithmetic
The arithmetic operations - addition, subtraction,
multiplication and division, performed on the binary
numbers is called binary arithmetic. The basic
arithmetic operations performed on the binary
numbers are
Binary conversion
Binary Addition, and
Binary Subtraction,
Binary Conversion
This involves converting a number in binary from to either
denary (base 10), octal (base 8) or hexadecimal( base 16)
(1) Conversion from decimal (denary) 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.
The answer is therefore 101002
(2) Binary to decimal conversion
Raise each bit to its binary power equivalent, from right going to the left,
starting at 20.
To calculate a large binary number like 10101000 we need more place values of
multiples of 2.
· 27 = 128
· 26 = 64
· 25 = 32
· 24 = 16
· 23 = 8
· 22 = 4
· 21 = 2
· 20 = 1
In denary the sum is calculated as:
(1x2 ) + (0 x 2 ) + (1 x 2 ) + (0 x 2 ) + (1 x
7 6 5 4
2 ) + (0 x 2 ) + (0 x2 ) + (0x2 ) = 168
3 2 1 0
= 1168
(4) Octal to decimal
Power 82 8 1 80
Equivalent to: 64 8 1
Octal Digits 1 1 6
= (64 x 1) + (8 x 1) + (1 x 6) = 78
Converting Binary To Octal
The relationship between binary and octal numbers
is that octal (8) is 23. Thus binary bits are put in
groups of 3, 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.
Each group is then separately converted to its
decimal equivalent, which will automatically be in
base 8.
Converting Binary to Octal
Step-1 Divide the binary number into groups of
three digits starting at the LSB. 111 101
Step-2 Write down the decimal equivalent for each
group of digits.
For example, convert 1000111010101 to octal:
i. the groupings in 3s will be as follows: 001 000 111 010
101
ii. 001, converted to decimal is = 1
000 becomes 0
111 becomes 7
010 becomes 2
101 becomes 5
The answer therefore becomes 107258
(5) 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 not append 0s to
the left
Take the binary digits and join them into one binary number.
(5) Decimal to hexadecimal
Hexadecimal means base 16.
A hexadecimal number contains numbers from 0 to 15.
However, 10 to 15 are represented by uppercase alphabetic
characters from A to F respectively.
The table below illustrates this:
DECIMAL NUMBER 0 1 2 3 4 5 6 7 8 9 1 11 12 13 1 15
0 4
HEXADECIMAL NUMBER 0 1 2 3 4 5 6 7 8 9 A B C D E F
(6) Binary to hexadecimal
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,
which will automatically be in base 16.
(7) 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. Take the binary digits and join them into one binary number
As on binary, take the number, divide it by 16 and take the remainders only,
e.g.
209 to hexadecimal will be expressed as:
1001ten Quotient
Divisor 1000ten | 1001010ten Dividend
-1000
10
101
1010
-1000
10ten Remainder
At every step,
• shift divisor right and compare it with current dividend
• if divisor is larger, shift 0 as the next bit of the quotient
• if divisor is smaller, subtract to get new dividend and shift 1 40
1001ten Quotient
Divisor 1000ten | 1001010ten Dividend
At every step,
• shift divisor right and compare it with current dividend
• if divisor is larger, shift 0 as the next bit of the quotient
• if divisor is smaller, subtract to get new dividend and shift 1 41
42
Divide Example
• Divide 7ten (0000 0111two) by 2ten (0010two)
Iter Step Quot Divisor Remainder
0 Initial values 0000 0010 0000 0000 0111
1 Rem = Rem – Div 0000 0010 0000 1110 0111
Rem < 0 +Div, shift 0 into Q 0000 0010 0000 0000 0111
Shift Div right 0000 0001 0000 0000 0111
2 Same steps as 1 0000 0001 0000 1111 0111
0000 0001 0000 0000 0111
0000 0000 1000 0000 0111
3 Same steps as 1 0000 0000 0100 0000 0111
4 Rem = Rem – Div 0000 0000 0100 0000 0011
Rem >= 0 shift 1 into Q 0001 0000 0100 0000 0011
Shift Div right 0001 0000 0010 0000 0011
5 Same steps as 4 0011 0000 0001 0000 0001 43
Multiplication of Binary
Binary multiplication
- is actually much simpler to calculate than decimal multiplication
because in binary multiplication, we only need to remember the
following,
0x0=0
0x1=0
1x0=0
1x1=1
*Note that since binary operates in base 2, the multiplication rules
we need to remember are those that involve 0 and 1 only.
As an example of binary multiplication we have 101 times
11,
101
X11
First we multiply 101 by 1, which produces 101. Then we
put a 0 as a placeholder as we would in decimal
multiplication, and multiply 101 by 1, which produces 101.
101
x11
101
1010 <-- the 0 here is the placeholder
The next step, as with decimal multiplication, is to
add. The results from our previous step indicates
that we must add 101 and 1010, the sum of which is
1111.
101
x11
101
+1010
1111
Explain how the binary value of 78 can be used to write down
the equivalent octal value with a minimum amount of
calculation.
- The binary value of 78 is 01001110.
- Put this binary number in groups of 3 starting from the right, and this
gives us 001 001 110.
- Each group of 3 bit can be converted separately to denary or octal form
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 decimal point in an integer is implied and does not change its position.
The register used to store an integer value will be as follows:
* * * * * * * *
There is no memory space for the decimal point. However computers
represent a finite number of digits. This limitation allows us to evaluate the
maximum and minimum possible numbers that can be represented. These
include:
- 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
The overall range of numbers here is -2n-1 to 2n-1-1
- 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:-
Negative numbers start with a 1. This gives us 1.1111111 =
-1/27=0.0078125
- Largest Magnitude Negative Number:-
This is 1.0000000 = -1
The decimal point is fixed at one position and therefore does not move. In
binary we can have functional column headings.
27 26 25 24 23 22 21 20 2-1 2-2
128 64 32 16 8 4 2 1 0.5 0.25
1 0 1 0 0 1 0 0. 1 1
=164.75
0 110000000 000001(Normalised)
II. 0 000010111 000110
0.000010111 exponent =6
0.10111 exponent =6-4
0.10111 exponent =2