Uploaded by Srinivas Vadali

Computer Science - Information Representation - Chapter 1

advertisement
Computer Science
Chapter1: Information representation
Year 12
_____________________________________________________________
Number Systems:
Denary numbers
Denary numbers which are also known as decimal numbers are written using one of the symbols
0,1,2,3,4,5,6,7,8,9 for each denary digit.
When a number is written down the value that it represents is defined by the place values of the digit in
the number. This can be illustrated by considering the denary number 346 which is interpreted as shown
in table.
Place value
Digit
Product of digit and place value
10^2 =100
10^1=10
10^0=1
3
4
6
300
40
6
Binary numbers
The binary number system is base-2. Each binary digit is written with either of the symbols 0 and 1. A
binary digit is referred to as a bit.
Bit: A digit in the binary number system written using either of the symbols 0 or 1.
As with a denary number, the value of a binary number is defined by place values. For example, see table
for the binary number 101110.
Place value
Digit
Product of digit and
Place value
2^5 =32
1
32
2^4=16
0
0
2^3=8
1
8
2^2=4
1
4
2^1=2
1
2
2^0=1
0
0
By adding up the values in the bottom row you can see that the binary number 101110 has a value which
is equivalent to the denary number 46.
Byte: A group of eight bits treated as a single unit.
Hexadecimal numbers
These are base-16 numbers where each hexadecimal digit is represented by one of the following symbols:
0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F.
The symbols A through to F represent the denary values 10 through to 15. The values of a number is
defined by place values. For example, see table for the hexadecimal number 2A6.
Place value
Digit
Product of digit and Place Value
16^2=256
2
512
16^1=16
A
160
16^0=1
6
6
Nibble: A group of four bits
A nibble can be represented by one hexadecimal digit. This means that each byte of binary code can be
written as two hexadecimal digits.
Two examples are shown in Table together with their denary equivalent.
Binary
00001010
11111111
Hexadecimal
0A
FF
Denary
10
255
TASK 1.01
Convert each of the denary numbers 96, 215 and 374 into hexadecimal numbers.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Convert each of the hexadecimal numbers B4, FF and 3A2C to denary numbers.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Question 1.01
Does a computer ever use hexadecimal numbers?
Ans: Hexadecimal numbers are often used as a beneficial method of data representation in computer science.
It takes fewer digits to represent a given value in hexadecimal than in binary.
One hexadecimal digit can represent four bits of binary data.
It is beneficial to use hexadecimal over binary because:
The more bits there are in a binary number, the harder it is to read.
Numbers with more bits are more prone to errors when being copied.
Numbers and quantities
There are several different types of numbers within the denary system. Examples of these are provided.
Type of number
Integer
Signed Integer
Fraction
A number with a whole
number part and a fractional
number part
A number expressed in exponential
notation
Examples
3 or 47
-3 or 47
2/3 or 52/17
-37.85 or 2.83
-3.6 X 10^8 or 4.2 X 10^-9
Comments
A whole number used for counting
The positive number has an implied +
Sign
Rarely used in computer science
The positive number has an implied
+sign
The value can be positive or negative
and the exponent can be positive or
negative.
Different ways to express a value using the denary number system.
Decimal prefix name
Symbol used
Factor applied to the value
kilo
K
10^3
Mega
M
10^6
Giga
G
10^9
Tera
T
10^12
The decimal prefixes
Decimal Prefix: A prefix to define the magnitude of a value. Examples are kilo, mega, giga and tera representing
factors of 10^3, 10^6, 10^9 and 10^12 respectively.
Binary prefix name
Symbol used
Factor applied to the value
kibi
Ki
2^10
mebi
Mi
2^20
gibi
Gi
2^30
tebi
Ti
2^40
The Binary prefixes
Binary Prefix: A prefix to define the magnitude of a value. Examples are kibi, gibi, and tebi representing factors of
2^10, 2^20, 2^30 and 2^40 respectively.
Internal coding of numbers:
One’s complement: The binary number obtained by subtracting each digit in a binary number from 1. This
means that each 0 is switched to 1 and each 1 switched to 0.
Two's complement: The One’s complement of a binary number, plus 1.
Binary arithmetic:
For binary addition, starting at the least significant position still applies. The rules for the addition of binary digits
are:
 0+0=0
 0+1=1
 1 + 1 = 0 with a carry of 1
 1 + 1 + 0 = 0 with a carry of 1
 1 + 1 + 1 = 1 with a carry of 1
The last two rules are used when a carried 1 is included in the addition of two digits.
As an example, the addition of the binary equivalent of denary 14 to the binary equivalent of denary 11 can be
examined.
+
1
1
0
1
1
1
1
1
0
______________________
1
0
0
1
The rules have correctly produced the 5 – bit answer which is the binary equivalent of 25.
Overflow: A condition when the result of a calculation is too large to fit into the number of bits defined for
storage.
Binary coded decimal (BCD)
One exception to grouping bits in bytes to represent integers is the binary coded decimal (BCD) scheme.
The BCD code uses a nibble to represent a denary digit.
The denary digit 8503 could be represented by either of the codes.
One BCD digit per byte
00001000
Two BCD digits per byte
00000101
10000101
00000000
00000011
00000011
Let’s consider how BCD arithmetic might be performed by a computer if fixed-point decimal values for currency
were stored as BCD values. Here is an example of addition.
Internal coding of text:
To store text in computer, we need a coding scheme that provides a unique binary code for each distinct individual
component item of the text.
ASCII Code:
The scheme which has been used for the longest time is the ASCII (American Standard Code for Information
Interchange) coding scheme.
The 7-bit version of the code (Often referred to as US ASCII) was standardised many years ago by ANSI (American
National Standards Institute).
Images
Images can be stored in a computer system for the eventual purpose of displaying the image on a screen or for
presenting it on paper, usually as component of a document.
Vector graphics:
In an image that is created by a drawing package or a computer-aided design (CAD) package each component is an
individual drawing object. The image is then stored, usually as a vector graphic file.
A graphic consisting of drawing objects defined in a drawing list.
A simple example of a vector graphic image
Bitmaps
Most images do not consist of geometrically defined shapes, so a vector graphic representation is inappropriate.
Generally, an image is stored as a bitmap.
Picture element (pixel): The smallest identifiable component of a bitmap image, defined by just two properties:
its position in the bitmap matrix and its colour.
Colour depth: The number of bits used to represent one pixel.
Bit depth: The number of bits used to represent each of the red, green and blue colours.
Image resolution: The number of pixels in the bitmap file defined as the product of the width and the height
values.
Screen resolution: The product of width and height values for the number of pixels that the screen can display.
File header: A set of bytes at the beginning of a bitmap file which identifies the file and contains information
about the coding used.
Sound:
Natural sound consists of variations in pressure which are detected by the human ear.
Analogue data: Data obtained by measurement of a physical property which can have any value from a
continuous range of values.
Digital data: Data that has been stored as a binary value which can have one of a discrete range of values.
Sampling: Taking measurements at regular intervals and storing the value.
Sampling resolution: The number of bits used to store each sample.
Sampling rate: The number of samples taken per second.
Compression techniques
Large files require large storage capacity but more importantly, large 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. The first is lossless compression where the file size is reduced but no
information is lost.
The second is lossy compression where 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 is used.
Exam-style questions:
1. A file contains binary coding. The following are two successive bytes in the file:
10010101 and 00110011
a. One possibility for the information stored is that the two bytes together represent one unsigned
integer binary number.
I.
Calculate the denary number corresponding to this.
II.
Calculate the hexadecimal number corresponding to this.
b. Give one example of when a hexadecimal representation is used.
c. Another possibility for the information stored is that two bytes individually represent two signed
integer binary numbers in two’s complement form.
I.
State which byte represents a negative number and explain the reason for your choice.
II.
Calculate the denary number corresponding to each byte.
d. Give two advantages of representing signed integers in two’s complement form rather than using a
sign and magnitude representation.
e. Give three different examples of other options of the types of information that could be represented
by two bytes. For each example, state whether a representation requires two bytes each time, just
one byte or only part of a byte each time.
Ans:
a. I) First byte: 10010101
Second byte: 00110011
Now, add them together:
10010101
00110011
---------------11001000
The decimal (denary) equivalent of the binary number 11001000 is indeed 200. So, the correct denary
representation of the two bytes together is 200.
II)
To calculate the hexadecimal number, you can group the bits in sets of 4 and convert them to
hexadecimal:
1001 0101 0011 0011 = 95 33 (in hexadecimal).
b. Hexadecimal representation is often used in computer programming and digital systems to represent
memory addresses, colors in HTML/CSS, and as a concise way to represent binary data.
I. In two's complement form, the leftmost bit represents the sign (0 for positive, 1 for negative). In this case, the
byte "10010101" represents a negative number because it starts with "1."
II. To calculate the denary numbers for each byte:
For "10010101": First, flip all bits (invert) and add 1 to find the absolute value: 01101011, then convert it to
decimal, which is 107.
For "00110011": Since it starts with "0," it represents a positive number, so the denary value remains the same,
which is 51.
d. Two advantages of representing signed integers in two's complement form are:
It simplifies addition and subtraction operations because they can be performed using the same binary addition
rules, regardless of sign.
There is no need for a separate sign bit, which saves storage space and simplifies arithmetic operations in
hardware.
e. Three different examples of types of information that could be represented by two bytes, indicating whether
each representation requires two bytes each time, just one byte, or only part of a byte each time:
RGB Color: Two bytes can represent a color, with each byte storing the intensity of a primary color (e.g., red,
green, or blue). Each byte can represent 256 different shades, so you would need two bytes for full color
information.
ASCII Character: One byte can represent a character using the ASCII encoding, which covers the standard
characters in the English alphabet and some special symbols.
Temperature: Two bytes can represent temperature readings in a specific format, where one byte indicates the
integer part, and the other byte represents the fractional part. This allows for a wide range of temperature values
with precision.
For the conversion of denary 374 the slow but steady route is via an initial conversion to binary using successive
division by two, noting the remainder each time and then reversing the remainders. The remainders are 0 1 1 0 1
1 1 0 1 which in reverse give the binary as: 101110110. For conversion to hexadecimal, groupings of four bits are
converted starting at the least significant (RHS) end. The 0110converts to 6, the 0111 to 7 so the hexadecimal
representation is 176. The more able students will use a short cut. Noting that 374 is greater than 16
2
a three-digit hexadecimal representation is expected. Calculating 374 – 256 leaves 118. This canbe seen to consist
of 7 16s with 6 remaining, hence 176.The conversion of 3A2C is best handled with a calculator via 3 x 16 = 48 then
+ 10=58 then x 16 = 928 then + 2 = 930 then x 16 = 14 880 then + 12 = 14 892. Notethat calculators are not
allowed in the 9608 exam so a conversion with such a largevalue is unlikely to occur
Download