Вы находитесь на странице: 1из 21

Information Representation

Learning Objectives
In this session, you will be able to:
(a) show understanding of the basis of different number systems
and use the binary, denary and hexadecimal number system
(b) convert a number from one number system to another
(c) express a denary number in Binary Coded Decimal (BCD) and
vice versa
(d) describe practical applications where BCD is use
(e) express a positive or negative integer in two’s complement form
(f) show understanding of, and be able to represent, character data
in its internal binary form depending on the character set used
Denary Data

 A digit is a single place that can hold numerical values between 0 and 9.
Digits are normally combined together in groups to create larger numbers.
For example, 6,357 has four digits.
 It is understood that in the number 6,357, the 7 is filling the "1s place,"
while the 5 is filling the 10s place, the 3 is filling the 100s place and the 6 is
filling the 1,000s place. So you could express things this way if you wanted
to be explicit:
(6 * 1000) + (3 * 100) + (5 * 10) + (7 * 1) = 6000 + 300 + 50 + 7 = 6357
 Another way to express it would be to use powers of 10. Assuming that we
are going to represent the concept of "raised to the power of" with the "^"
symbol (so "10 squared" is written as "10^2"), another way to express it is
like this:
(6 * 10^3) + (3 * 10^2) + (5 * 10^1) + (7 * 10^0) = 6000 + 300 + 50 + 7 = 6357
Binary Data

 Computers can only process binary data – i.e.


1’s and 0’s. If numeric data is to be processed
then it cannot be processed in its usual base10
form, it must be converted into its base2 form –
known as binary.
 There are two ways that can be used to
represent numbers in binary:
 ”pure” binary;
 binary-coded decimal (BCD).
Pure Binary

 Pure binary represents numbers using just two digits (‘0’ and ‘1’)
and columns, which increase by a factor of two.
 This is in contrast to our normal number system (denary), which
uses ten digits (0-9) and columns, which increase by a factor of
ten.
 A binary number, such as 1001 0101, can be converted into its
denary equivalent as follows:
1. Write the binary number with the appropriate column headings:
128 64 32 16 8 4 2 1
1 0 0 1 0101
2. Add the column headings under which there is a binary ‘1’:
= 128 + 16 + 4 + 1 = 149
Pure Binary

 A denary number, such as 107, can be converted into binary as follows:


1. Write down the binary column headings:
128 64 32 16 8 4 2 1
2. Then, starting from the left, ‘take out’ the values in the column headings, if possible:
 128 cannot be taken out of 107 so that column contains a ‘0’:
128 64 32 16 8 4 2 1
0
 64 can be taken out of 107 so that column contains a ‘1’; this leaves 107 – 64 = 43:
128 64 32 16 8 4 2 1
0 1
 keep repeating the above process until the whole number has been converted to
pure binary:
128 64 32 16 8 4 2 1
0 1 1 0 1011
Binary Addition
Binary Coded Decimal

 Binary Coded Decimal is


one of the early memory
encodings. Rather than
converting the entire
denary value into its pure
binary form, it converts
each digit, separately,
into its 4-bit binary
equivalent. The table
below shows the 4-bit
BCD equivalents of the
ten denary digits:
Binary Coded Decimal

 Note that the higher codes are not used in BCD


because they do not represent a denary digit.
These are:
Binary Coded Decimal
Advantages of BCD

The advantage of the BCD representation is the ease of


conversion from BCD to decimal and vice versa. For
example, when binary numbers have to be
electronically decoded for a pocket calculator display, a
number held in BCD format simply has to be split into
groups of four bits and each group converted directly to
the corresponding decimal digit.
When storing fractional numbers, a further advantage of
the BCD representation is that since each decimal digit
is encoded separately, using as many bits as
necessary to represent the complete number exactly,
no ‘rounding’ of numbers occurs.
Disadvantages of BCD

More bits are required to store a number than when using pure binary.
Another disadvantage is that calculations with such numbers are more
complex than with pure binary numbers. For example, adding 1 and 19:
0000 0001
0001 1001 +
0001 1010
The problem arises because only the first ten out of 16 combinations of four digits are
used. Therefore, whenever the sum of two binary digits is greater than 9, six (6)
has to be added to the result in order to skip the six unused codes.
0001 1010
0110 +
0010 0000
Hexadecimal Number

 The hexadecimal number system uses 16 digits to represent


numbers. The denary digits 0 – 9 are used together with the
first six letters of the alphabet (A – F).
 Examples of hexadecimal numbers include: 3FC2, CFF8,
92B0, EE4D, ACDC.
 Note that the number 9375 could either be ordinary denary
or hexadecimal – to make it clear the symbols ‘h’, ‘#’ or ‘&’
are often used. Thus, if the number was in hexadecimal, it
would be written as 9375h, #9375 or &9375.
 Hexadecimal is often used by Assembly language programmers
to reference memory. It is also used within HTML property
values – specifically background and font colours.
Hexadecimal Number
Hexadecimal Number
Advantages of Hexadecimal
numbers
 There are three advantages of using
hexadecimal:
 hexadecimal is quicker for a programmer to
enter into a computer than binary;
 hexadecimal is easier for a programmer to

understand and remember – 8F8B is easier


to remember than 1000111110001011.
 it is very easy to convert between binary to

hexadecimal. For example, FAD7 hex is


1111 1010 1101 0111 (F=1111, A=1010,
D=1101, 7=0111) in Binary.
Negative integers in Two’s
complement form
Nearly all computers work purely in binary. That means that they
only use ones and zeros, and there's no – or + symbol that the
computer can use. The computer must represent negative
numbers in a different way.
We can represent a negative number in binary by making the most
significant bit (MSB) a sign bit, which will tell us whether the
number is positive or negative. The column headings for an 8 bit
number will look like this:
-128 64 32 16 8 4 2 1
MSB LSB
1 0 1 1 1 1 0 1
The example above is -67 in denary because: (-128 + 32 + 16 + 8
+ 4 + 1 = -67).
Character Set and Encoding

 A character set are the characters that can be recognised by a


computer.
Character encoding
 A computer is able to represent four types of characters:
 alphanumeric characters – letters A – Z and a – z and the digits 0
– 9.
 punctuation characters and other ‘special’ symbols such as , . ; : “
‘!@£$%&*()+<
 graphical characters such as ♣, ♦, ♥, ♠, Ψ, , , ✘, ☛, ✻ (and
many more...);
 control characters – [Return], [Esc], [Space], [Alt], etc.
 Within a computer, each character is represented using a unique
binary code. Although there are many different methods of encoding
the characters, two of the most common are ASCII, and Unicode.
American Standard Code for
Information Interchange (ASCII)
Bytes are frequently used to hold individual characters in a text
document. In the ASCII character set, each binary value
between 0 and 127 is given a specific character.
Most computers extend the ASCII character set to use the full
range of 256 characters available in a byte. The upper 128
characters handle special things like accented characters from
common foreign languages.
Computers store text documents, both on disk and in memory,
using these codes. For example, if you use Notepad in Windows
OS to create a text file containing the words, "Four score and
seven years ago," Notepad would use 1 byte of memory per
character (including 1 byte for each space character between
the words -- ASCII character 32). When Notepad stores the
sentence in a file on disk, the file will also contain 1 byte per
character and per space.
ASCII
How character encoding works

 The diagram below shows how the message “Hello World” is stored in the
memory of a computer using the ASCII codes:

 The message is typed at the keyboard. Electronics in the keyboard convert


the typed characters into ASCII binary codes that are sent from the keyboard
along a cable to the computer.
 The computer stores these codes in its internal memory. The computer also
provides a visual display of the characters as they are typed. To be able to
do this, electronics inside the computer convert the stored binary codes back
into their character equivalents.
Unicode

 Unicode is an international system


of representing characters using
16 bits. Using 16 bits means that
216 = 65 536 different characters
can be represented (thus
overcoming the limitation of ASCII
and EBCDIC).
 Unicode allows every character
from most alphabets to have a
code of its own – Chinese,
Russian, Greek, Urdu etc,
including Egyptian Hieroglyphics.
 Note that there are plenty of spare
codes that are used for
mathematical symbols, common
graphics and even the Braille
symbols.