1 - Digitalist

Download Report

Transcript 1 - Digitalist

3 Computing System
Fundamentals
3.5 Data Representation
1
3.5.1 Binary
Decimal
• The decimal (base 10) number 287 means
‣
‣
‣
2 hundreds,
8 tens and
7 ones.
• Each column leftwards represents an
increase in magnitude by x10 (powers of 10,
0
1
2
i.e. 10 , 10 , 10 ...
3
Decimal
• The decimal number 7451:
LSD
MSD
Thousands
103
7
Hundreds
102
4
Tens
101
5
• MSD = most significant digit
• LSD = least significant digit.
4
Ones
100
1
Binary
• Counting in tens is an accident of
evolution
(most of us have 10 fingers).
• Computers are built from millions of on/off
switches, so it is more logical for them to work
in base 2 (binary).
• The only allowed digits are 0 and 1 (binary
digits or bits).
5
Binary
•
MSB
LSB
Bit no.
7
6
5
4
3
2
1
0
Power of 2
27
26
25
24
23
22
21
20
Which is
128
64
32
16
8
4
2
1
Number in
binary
0
1
0
0
1
0
0
1
Representin
g
64
8
and 64 + 8 + 1 = 73 in decimal
• MSB = most significant bit.
6
1
Binary
• As with decimal, a leading zero is usually
dropped i.e.
01001001 = 1001001.
• Subscripting is used to denote the base you
are working in:
i.e.
7310 = 10010012
• If there is no subscript and you are not told
the base, assume it is decimal.
7
Uses of binary
• ASCII (American Standard Code for
Information Interchange) is a binary code
used to represent characters.
• Each letter, digit and symbol is represented
by a unique code e.g. 01000001 is the capital
letter A, (represented as the decimal number
65 in a table of ASCII characters).
8
Uses of binary
• In standard ASCII, only the first 7 bits are
used so the LSB can be used as a parity bit
when characters are transmitted across a
network.
• This allow 2
7
= 128 combinations and
therefore 128 keyboard characters, which is
enough for the common western European
languages.
9
Uses of binary
• To accommodate non-Latin characters, most
operating systems (and Java) now use
Unicode , which uses 2 bytes per character.
• Using 16 bits allows 2
16
or 65 536 possibilities
i.e. the more bits you use the greater the
range of data you can represent.
• This is enough to cover other alphabets such
as Chinese and Arabic.
10
Uses of binary
• Bit patterns can be used to represent data
other than numbers or characters e.g. colours
• Very old computers might use 4 bit colour i.e.
16 colours in all i.e. every pixel has a 4 bit
colour code.
• 16 bit colour (65 536 colours) is referred to as
“thousands of colours”, 32 bit as “millions”.
11
Uses of binary
• Locations in computer memory need their
own unique address, which is a binary
number.
• Most PCs use a 32 bit address bus
i.e.
there are 232 or 4 294 967 296 possible
memory addresses in the RAM - such
computers cannot usually work with more
than about 4GB of RAM.
12