Number Representation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 65

Number representation

Denary number system is known as base 10 and it has


digits ranging from 0,1,2…8,9.

The value of a digit is determined by its position using the


following place values
106 105 104 103 102 101 100
1000000 100000 10000 1000 100 10 1

So a number like 643 implies 6X102 + 4x101 + 3 x 100


Number representation
Binary number system on the other hand is known as
base 2 and it has only 2 digits, either a 0 or a 1.

Similarly the value of a digit is determined by its position


using the following place values
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

So a binary number like 11011 implies 1X24 + 1X23 +


0X22 + 1X21 + 1X20 Which gives us 16 + 8 + 0 + 2 + 1 =
Converting from denary to binary
To convert from denary to binary you can use the scale
(placement)
For example converting 55 to binary
1. Place a ZERO under 68 because 68 is bigger than 55
2. Place a 1 under 32 and subtract 32 from 55 to remain with 23
3. Place a 1 under 16 and subtract 16 from 23 to remain with 7
4. 8 is bigger than 7 so place a 0 under 8
5. Place a 1 under 4 and subtract 4 from 7 to remain with 3
6. Place a 1 under 2 and subtract 2 from 3 to remain with 1
7. Place a 1 under 1 and subtract 1 from 1 to remain with 0 (so 55 = 1101112)
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
0 0 1 1 0 1 1 1
Converting from denary to binary
To convert from denary to binary you can use the scale
(placement)
For example converting 55 to binary
1. Place a ZERO under 68 because 68 is bigger than 55
2. Place a 1 under 32 and subtract 32 from 55 to remain with 23
3. Place a 1 under 16 and subtract 16 from 23 to remain with 7
4. 8 is bigger than 7 so place a 0 under 8
5. Place a 1 under 4 and subtract 4 from 7 to remain with 3
6. Place a 1 under 2 and subtract 2 from 3 to remain with 1
7. Place a 1 under 1 and subtract 1 from 1 to remain with 0 (so 55 = 1101112)
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
0 0 1 1 0 1 1 1
Converting from denary to binary
Using the placement scale (placement) method convert
the following denary numbers to binary
a41
c86
d100
f127
h189
j255 7
2 2 6
2
5
24
2
3 2
2 2
1
2
0

128 64 32 16 8 4 2 1
Converting from denary to binary (Method 2)

The boring long division method is easier than the


placement method but it’s a slower method and prone to
errors. This method should be left to ecd children
Converting 55 to binary using the long division keeping the remainder.
2 55 Remainde
r
2 22 1 We read from the bottom going up and
2 11 0 hence the Answer is 101101 which is the
same answer we got using the
2 5 1
placement method
2 2 1
2 1 0
2 0 1
Converting from binary to denary
Converting a binary number to decimal is a simple
reversal of the conversion discussed earlier on.
1. Place the binary digits on the scale
2. Multiply each binary digit with its place value
3. Add the result to get the equivalent denary value

Example convert 110101 to denary


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

So we get 0x68 + 1x32 + 1x16 + 0 x 8 + 1x 4 + 0x2 + 1x1


= 0 + 32 + 16 + 0 + 4 + 0 + 1
= 53
Converting from binary to denary
Using the placement scale (placement) method convert
the following binary numbers to denary
b01111111
d01110100
f00001111
h11110000
j11101110
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
Measurement of memory
A binary digit BIT is either a one or a zero
A byte is a collection of 8 bits
A nibble is a group of 4 bit
A word length is the number bits which a computer can
process at once for example 16 bit 32 bit or 64 bit
Measurement of memory
Measuring in Kilo, Mega, Giga Measuring in Kibi, Mebi, Gibi
Name of memory Number of Equivalent Name of memory Number of Equivalent
size bits denary value size bits denary value

1 Kilobyte (1Kb) 103 1000 Bytes 1 Kibibyte (1Kb) 210 1024 bytes
1 Megabyte (1Mb) 106 1000000 Bytes 1 Mebibyte 220 1,048,576
1 Gigabyte (1Gb) 109 1 000 000 000 1 Gibibyte 230 1 073 741 824
bytes bytes
1 Terabyte (1Tb) 1012 1 000 000 000 1 Tebibyte (1Tb) 240 1 099 511 627
000 bytes 776 bytes
1 Petabyte (1Pb) 1015 100 000 000 1 Pebibyte (1Pb) 250 125 899 906
000 000 bytes 842 624 bytes
1 exabyte (1Eb) 1018 1 exbibyte (1Eb) 260
Octal Number system
The octal number system is no longer in use. It is also
known as base 8 and its digits run from 0,1,2..7

To convert from decimal to octal you can use the place


value method or the long division (dividing by 8) just in
the same way you convert from decimal to binary.
Hexadecimal Number system
The hexadecimal number system (base 16) is widely
used in computing because it is shorter than binary and
therefore occupies less space and makes it easier to
identify errors.

Hexadecimal number system is used to


Convert the following binary numbers hexadecimal
• 11010011
• 10000011
• 100000000
• 111111110
Convert the following hexadecimal numbers to binary
• 3FC
• 1FA
• 100
Convert the following denary number to hexadecimal
• 25
Binary addition and subtraction
Convert the following binary numbers hexadecimal
• 11010011
• 10000011
• 100000000
• 111111110
Convert the following hexadecimal numbers to binary
• 3FC
• 1FA
• 100
Convert the following denary number to hexadecimal
• 25
Binary addition and subtraction
Complete the following binary addition. Show your working.
11010011
+0 1 0 1 1 0 0 1

Complete the following binary subtraction. Show your working.


11010011
-0 1 0 1 1 0 0 1
Task
Complete the following binary addition. Show your working.
10110111
+0 0 1 0 1 0 1 0

Complete the following binary subtraction. Show your working.


10010001
-0 1 0 0 1 0 1 1
Binary addition
One of the colours used in the image has the hexadecimal colour code:
#FC238A

FC is the amount of red, 23 is the amount of green and 8A is the amount of blue in the colour.
(i) Convert the hexadecimal code FC into denary.
...................................................................................................................................[1]
(ii) The amount of green in binary is 00100011. This has the denary number 15 added to it to create
a second colour.

Add the denary number 15 to the binary number 00100011 and give your answer in
binary.

Perform the addition in binary. Show your working.


Working .........................................................................................................
.......................................................................................................................................
.......................................................................................................................................
Answer (in binary) .....................................[3]
Internal coding of numbers
Computers have to store integer values for a number of purposes.
Sometimes the requirement is only for an unsigned integer to be stored.
However, in many cases a signed integer is needed where the coding
has to identify whether the number is positive or negative.

An unsigned integer can be stored simply as a binary number. The only


decision to be made is how many bytes should be used.

If a signed integer is to be represented, the obvious choice is to use one


bit to represent the+ or - sign. The remaining bits then represent the
value. This is referred to as 'sign and magnitude representation'
one’s and two’s complement
Ones complement
The binary number obtained if each binary digit is individually
subtracted from 1 which, in practice, means that each O is switched to 1
and each 1 switched to 0.

Two’s complement
The binary number obtained if 1 is added to the one's complement
number.

For a quicker method to convert to two’s complement you start at the least
significant bit and move left ignoring any zeros up to the first 1 which is also ignored.
Any remaining bits are then changed from Oto 1 or from 1 to 0.
Sign and magnitude vs two’s complement
one’s and two’s complement
• sign and magnitude representation has a positive and a negative zero
which could cause a problem if comparing values.
• there is an extra negative value represented in two's complement.
• representations in two's complement are such that starting from the
lowest negative value each successive higher value is obtained by
adding 1 to t he binary code. In particular, when all digits are 1 the
next step is to roll over to an all-zero code. This is the same as any
digital display would do when each digit has reached its maximum
value.
Converting two’s complement to denary
Convert 10010110 in two’s complement to denary

1. Change back to ‘normal binary’ and we get


01101010
2. Covert to denary
0X128+ 1x64 + 1x32 + 0x16 + 1x8 + 0x4 +1x2 + 0x1

= -106
OR
Convert 10010110 in two’s complement to denary

Assign each digit its place value keeping in mind that the most
significant bit is negative
-1X128+ 0x64 + 0x32 + 1x16 + 0x8 + 1x4 +1x2 + 0x1

= -128 +16 + 4 +2
= -106
Qs
Using two’s complement, show how the following denary numbers could
be stored in an 8-bit register:

(i) 114

(ii) -93

(iii) 124

(iv) -77
Binary coded decimal (BCD)
If there is an application where single denary digits are required to be
stored or transmitted, BCD offers an efficient solution. The BCD code
uses four bits (a nibble) to represent a denary digit.

There are, however, two options for BCD; the first is to store one BCD code in one
byte leaving four bits unused. The other option is packed BCD where two 4-bit
codes are stored in one byte.

Example
BCD applications
• on the screen of a calculator or in a digital time display.
• representation of currency values.

Arithmetic addition error


Qs
Binary Coded Decimal (BCD) is another way of
representing numbers.
(i) Write the number 359 in BCD form.
[1]
(ii) Describe a use of BCD number representation.
[2]

Assignment
Read on internal coding of text ASCII and Unicode

Next up
1.05 Images
Qs
Thank you for covering internal coding of text ASCII and
Unicode

Test 1
Images
There are various sources of images. An image can be created by
using an appropriate graphics package (name graphic creation
packages you are familiar with). Alternatively, when an image already
exists independently of the computer system, the image can be
captured by using photography or by scanning.

There are two main forms for storing images, namely vector graphics
and bitmap images.
Images
There are various sources of images. An image can be created by
using an appropriate graphics package (name graphic creation
packages you are familiar with). Alternatively, when an image already
exists independently of the computer system, the image can be
captured by using photography or by scanning.

There are two main forms for storing images, namely vector graphics
and bitmap images.
Vector graphic
A vector graphic file contains a drawing list. The list contains a command for
each object included in the image.

Each command has a list of attributes, each attribute defines a property of the
object. The properties include the basic geometric data such as, for a circle, the
position of the centre and its radius. In addition, properties are defined such as
the thickness and style of a line, the colour of a line and the colour that fills the
shape.
Vector graphic
Whenever the image is to be displayed the file is read, the appropriate
calculations are made and the objects are drawn to a suitable scale. If the user
then requests that the image is redrawn at a larger scale the file is read again
and another set of calculations are made before the image is displayed. This
avoids image distortion, such as the image appearing squashed or stretched.

Note that a vector graphic file can only be displayed directly on a graph plotter,
which is an expensive specialised piece of hardware. For the image to appear
correctly on other types of display, the vector graphic file oft en has to be
converted to a bitmap.
Bitmaps
The fundamental concept underlying the creation of a bitmap file is that the picture
element (pixel) is the smallest identifiable component of a bitmap image. The image is
stored as a two-dimensional matrix of pixels. The pixel itself is a very simple construct; it has
a position in the matrix and it has a colour. It does not matter whether each pixel is a small
rectangle, a small circle or a dot.

The scheme used to represent the colour has to be defined. The simplest option is to use
one bit to represent the colour, so that the pixel is either black or white. Storage of the colour
in four bits allows simple greyscale colouring. At least eight bits per pixel are necessary to
provide a suff icient range of colours to provide a reasonably realistic representation of any
image. The number of bits per pixel is sometimes referred to as the colour depth.
Working space
1
Vector graphics
The fundamental concept underlying the creation of a bitmap file is that the picture
element (pixel) is the smallest identifiable component of a bitmap image. The image is
stored as a two-dimensional matrix of pixels. The pixel itself is a very simple construct; it has
a position in the matrix and it has a colour. It does not matter whether each pixel is a small
rectangle, a small circle or a dot.

The scheme used to represent the colour has to be defined. The simplest option is to use
one bit to represent the colour, so that the pixel is either black or white. Storage of the colour
in four bits allows simple greyscale colouring. At least eight bits per pixel are necessary to
provide a sufficient range of colours to provide a reasonably realistic representation of any
image. The number of bits per pixel is sometimes referred to as the colour depth.
Vector graphics
A colour depth of 8 bits per pixel provides 256 different colours. A bit depth of 8 bits per primary colour provides 256 × 256 ×
256 = 16 777 216 different colours. The eye cannot distinguish this number of different colours. However, this many are
needed if an image contains areas of gradually changing colour such as in a picture of the sky. If a lower bit depth is used the
image will show bands of colour.
Vector graphics
A bitmap file does not define the physical size of a pixel or of the
whole image. When the image is scaled the number of pixels in it
does not change. If a well-designed image is presented on a suitable
screen the human eye cannot distinguish the individual pixels.
However, if the image is magnified too far the individual pixels will be
seen.
Vector graphics
File size is always an issue with an image file. A large file occupies more memory space and takes longer to
display or to be transmitted across a network. Usually, a vector graphic file uses considerably less memory
space than a corresponding bitmap file.

You can calculate the size of a bitmap graphic knowing the resolution and the colour depth. As an example,
consider that a bitmap graphic is needed to fill a laptop screen where the resolution is 1366 by 768. If we want
colour depth of 24 then the number of bits we need is:

1366 × 768 × 24 = 25 178 112 bits

The result of this calculation shows the number of bits, but a size is always quoted as a number of bytes or
multiples of bytes. For our bitmap graphic:
25 178 112 bits = 25 178 112 ÷ 8 = 3 147 264 bytes
= 3 147 264 ÷ 1024 = 3073.5 kibibytes (3073.5 KiB)
= 3073.5 ÷ 1024 = approximately 3 MiB
Vector graphics
A bitmap file has to store the pixel data that defines the
graphic, but the file must also have a file header that
contains information on how the graphic has been
constructed. Because of this, the bitmap file size is
larger than the size of the graphic alone.
Vector graphics
The following are considerations when justifying the use of either a bit map or a
vector graphic for a specific task.

• A vector graphic is chosen if a diagram is needed to be constructed for part of


an architectural, engineering or manufacturing design.
• If a vector graphic file has been created but there is a need to print a copy
using a laser or inkjet printer the file has first to be converted to a bitmap.
• A digital camera automatically produces a bitmap.
• A bitmap file is the choice for insertion of an image into a document,
publication or web page.
Vector graphics
The following are considerations when justifying the use of either a bit map or a
vector graphic for a specific task.

• A vector graphic is chosen if a diagram is needed to be constructed for part of


an architectural, engineering or manufacturing design.
• If a vector graphic file has been created but there is a need to print a copy
using a laser or inkjet printer the file has first to be converted to a bitmap.
• A digital camera automatically produces a bitmap.
• A bitmap file is the choice for insertion of an image into a document,
publication or web page.
Calculating storage requirements

Data is store in bits and the following units are used

8 bits 1 byte or 1B
1024 bytes 1 kilobyte (1kb)
1024 kilobytes 1 megabyte (1MB) or 1048 576 bytes
1024 megabytes 1 gigabyte (1GB) or 1 073 741 824 bytes
1024 gigabytes 1 terabyte (1TB) or 1 099 511 627 776 bytes

To convert bits to bytes you divide by 8 and to convert bytes to kilobytes


you divide by 1024. Successive division by 1024 changes the units to
the next level.
Storing data

Data to be stored Storage requirements


Pixels in a black and white image 1 bit per pixel
Pixel in an 8-bit colour image 8 bits (1 byte) per pixel
Characters in an ASCII test string 1 byte (8bits) per character
Sound in a wave file 86 kilobytes per second
Uncompressed frame of standard-definition TV 27 megabytes per frame
Uncompressed frame of high-definition TV 182 megabytes per frame
Example 2 – Storing a simple B/W image

A back and white picture is stored as follows

The has 8 rows and 8 columns which gives us 64 pixels (8 X 8)


64 pixels X 1 bit per pixel = 64 bits
64 bits / 8 = 8 bytes
Example 3 – Storing an 8 bit colour image

A colour image is stored as follows

Since the image now has 8 bit colour, its needs 8 bits (1 byte to store the colour)
64 pixels X 8 bits = 512 bits
512 bits / 8 = 64 bytes
Example 4 – calculating file size from image
size and resolution.

A 24-bit colour image that is 2cm high X 3cm wide, with a


resolution of 300 dots per inch is to be stored.
To calculate the number of pixels we use the resolution of 300
dot per cm and the image dimension 0f 2 X 3, so its 600 pixels
(2 x 300) by 900 pixels (3 x 300) since it’s a 24-bit colour
image it would require 24 bit for each pixel excluding meta-
data 300 pixel x 900 pixels =270 000pixels
270 000pixels x 24 bits per pixel = 6 480 000 bits
6 480 000 bits / 8 810 000 bytes
810 000 bytes / 1024 791.02 kilobytes
791.02 kilobytes / 1024 0.77 megabytes
Activity 6.2 (Homework)
Activity 6.2
a. An image is 1200 pixels by 1600 pixels. Calculate:
i. the total number of pixels in the original image
ii. the number of bytes occupied by this file
iii. the file size of the jpeg image (in kilobytes) if the original
image was reduced by a factor of 8.
Activity 6.2
b. A second image is 3072 pixels by 2304 pixels. Calculate:
i the total number of pixels in the original image
ii the number of bytes occupied by this file
iii the file size of the jpeg image (in megabytes) if the original
image was reduced by a factor of 5.
iv How many uncompressed files of the size calculated in part
(ii) could be stored on a 4-gigabyte memory card?
v How many compressed files of the size calculated in part (iii)
could be stored on the same 4-gigabyte memory card?
Text and number file formats

Text and numbers can be stored in a number of formats. Text is


usually stored in an ASCII format When using spreadsheets or
databases, for example, numbers can be stored in a number of
different formats:
real e.g. 2.71678
integer e.g. 3
date e.g. 12/08/2016
time e.g. 19:45:50
currency e.g. R$ 15.50
Example 1 – Storing text

The following text is stored in a file


Welcome to Arundel School
This message contains 25 characters (including spaces).
Each character will use 1 byte in storage and therefore the
space occupied can be calculated as follows:

25 characters X 1 byte = 25 bytes


Sound

Sound consists of variations in pressure which the human ear


can detect. A typical sound contains a number of individual
waves each with a defined frequency.

Sound needs to be converted to binary form if it is to be stored


or transmitted electronically. The measured sound values are
put into an encoder which has 2 components:
1. Band-limiting filter
2. Analogue to digital converter
Sound

Band-limiting filter
It is used to remove high frequencies which the human ear
cannot detect. These high frequencies will cause problems if
converted.

Analogue-to-Digital converter
The analogue to digital converter simply converts the analogue
signals to digital.
Sound

The amplitude of the sound which is the changes in the


frequency will need to be recorded at a regular interval to come
up with an accurate representation of the sound wave.

The exact value of the amplitude cannot be measured exactly


but the closest representation is needed for an accurate
conversion.
Sound

To code sound, two decisions have to be made. The first is the


number of bits we will use to store the amplitude values, which
defines the sampling resolution. If we use only three bits then eight
levels can be defined. If too few are used there will be a significant
error when the closest amplitude in the scale of values dictated by
the sampling resolution is used as the approximation for the real
value. In practice, 16 bits provides reasonable accuracy for most
digitised sound.
Sound

To code sound, two decisions have to be made. The first is the


number of bits we will use to store the amplitude values, which
defines the sampling resolution. If we use only three bits then eight
levels can be defined. If too few are used there will be a significant
error when the closest amplitude in the scale of values dictated by
the sampling resolution is used as the approximation for the real
value. In practice, 16 bits provides reasonable accuracy for most
digitised sound.
? How many level can be defined by 16bits
Sound

We also need to choose the sampling rate, which is the


number of samples taken per second. This should be in
accordance with Nyquist’s theorem which states that
sampling must be done at a frequency at least twice the
highest frequency of the sound in the sample.
Sound
Compression techniques
Larger files require larger storage capacity but more importantly, larger files have lower
transmission or download rates. For this reason, compression techniques are often used to
reduce file size. There are two categories of compression.

1. Lossless compression
The file size is reduced but no information is lost. The process can be reversed to re-create
the original file.

2. Lossy compression
The file size is reduced with some loss of information and the exact original file can never be
recovered.

In many applications a combination of lossless and lossy methods are used.


Compressing Text

Compress the following to 40%

COMPARE TEXT FILES IN A COMPUTER AFTER FILE


COMPRESSION
Compression
A common lossless compression technique is run-length encoding. This works
particularly well with a bitmap file. The idea is that compression converts
sequences of the same byte value into a code that defines the byte value and
the number of times it is repeated (the count).

For example, the sequence of the same four bytes:


01100110 01100110 01100110 01100110
could be replaced by:
00000100 01100110
which says that there is a run of four of the bytes.
Compressing sound
If a file contains text, then compression must be lossless because any loss of
information would lead to errors in the text. One possible compression method
is called Huff man coding.

Instead of having each character coded in one byte, the text is analysed to find
the most often used characters. These are then given shorter codes. The
original stream of bytes becomes a bit stream.
Compressing sound

Huffman coding can also be used for compressing a sound file. This is
effective because some values for the amplitude occur far more often
than others do. If a vector graphic file needs to be compressed it is
best converted to a Scalable Vector Graphics format. This uses a
markup language description of the image which is suitable for
lossless compression.
Compressing sound

Huffman coding can also be used for compressing a sound file. This is
effective because some values for the amplitude occur far more often
than others do. If a vector graphic file needs to be compressed it is
best converted to a Scalable Vector Graphics format. This uses a
markup language description of the image which is suitable for
lossless compression.
Compressing sound
5 a Sound can be represented digitally in a computer.
Explain the terms sampling resolution and sampling rate. [4]
b The following information refers to a music track being recorded on a CD:
– music is sampled 44 100 times per second
– each sample is 16 bits
– each track requires sampling for left and right speakers.
i Calculate the number of bytes required to store one second of sampled music.
Show your working. [2]
ii A particular track is four minutes long.
Describe how you would calculate the number of megabytes required to store this track. [2]
c When storing music tracks in a computer, the MP3 format is often used. This reduces file
size by about 90%.
Explain how the music quality is apparently retained. [3]
End of chapter

Test 2
Next up – Communication and
networking technologies

You might also like