L01 - Data Representation (Part 1)

You might also like

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

Lecture 01 - Data Representation –

Part1

ITDR2102 - Computer Organisation

Reference:
Computer Organization and Architecture, 10th Ed., William Stallings.

ITDR2102 – Computer Organization 1


Lecture Overview
• What is Computer Architecture?
• What is data?
• Bits, bytes, words, characters and integers.
• Number systems — denary, binary, octal, hex.
• Character Codes.

ITDR2102 – Computer Organization 2


What is Computer Organization?
• Computer Organization: is the study of the details
of computer hardware.
• Usually we ignore architecture when doing high-
level programming – Java, C/C++.

• Why study computer Organization?


• Must know the computer architecture for Assembly
language programming or writing system software
such as device drivers.

ITDR2102 – Computer Organization 3


What Is Data?
• Corresponds to discrete facts about phenomena from which
we gain information about the world.
• The concept of value is fundamental to any kind of data.
• Some values are: 25, $255.50, -50, April, 'This is a sentence.’,
red, A#.
• BUT, values are abstract. They exist only in the mind.
• Examples: This is the month of February. This is the 58th day
of the year.
• The same value may be represented in many ways:
‒ 12 twelve XII 1100
‒  
‒  – – – –  – – –

ITDR2102 – Computer Organization 4


How Is Data Represented In a Computer?
• The digital computer is binary.
• Everything is represented by one of two states:
• 0, 1; on, off; true, false; voltage, no voltage.
• Values are represented by sequences of binary
digits or bits.

ITDR2102 – Computer Organization 5


Computer Memory
• In general, data being worked on is stored in the
computer's memory.
• Think of memory as a bunch of slots where we can
store stuff. 0
• Each slot (data item) has: 1
2 X
• an address (for the computer) 3
4
• a name (for us). 5 CH
6
• The slot name is an identifier used to identify
a location in the computer's memory.
1,048,569 A[1]
• During compilation, the name is translated 1,048,570 A[2]
into the actual address of the memory 1,048,571
1,048,572
location where the data item is stored. 1,048,573
1,048,574
1,048,575

ITDR2102 – Computer Organization 6


Bits, Bytes, Words
• The smallest unit of storage is the bit.
• The bit has a binary value, 0 or 1.
• Each memory location is made up of computer
word which is minimum 1 byte. 0
1
• A computer with 1 MB of memory 2 X
3
has 1,048,576 bytes (2 ).
20 4
5 CH
• A computer with 1 GB of memory has 6

1,073,741,824 bytes (230).


1,048,569 A[1]
1,048,570 A[2]
1,048,571
1,048,572
7 0 1,048,573
1,048,574
MSB LSB 1,048,575

ITDR2102 – Computer Organization 7


A Word of Memory
• Word is a manufacturer defined constant.
• The size of the memory location is a word.
• The minimum word size is one byte.
• A byte (8 bits) is typically the smallest addressable
unit.
• Nowadays, the typical word size is 32 or 64 bits.

ITDR2102 – Computer Organization 8


Characters
• A character is the smallest unit of data that people
normally handle.
• Characters include:
• UPPER CASE LETTERS: A C X . . .
• lower case letters: b g k ...
• Single digits: 3 1 9 ...
• Special characters: ! < = ...
• Others: <tab>, <eol>, <eof>, …

ITDR2102 – Computer Organization 9


Storage Units
Byte (B) 8 Bits

Kilobyte KB 210 Bytes 1,024 Bytes

Megabyte MB 220 Bytes 1,048,576 Bytes

Gigabyte GB 230 Bytes 1,073,741,824 Bytes

Terabyte TB 240 Bytes 1,099,511,627,776 Bytes

Petabyte PB 250 Bytes 1,125,899,906,842,624 Bytes

Exabyte EB 260 Bytes 1,152,921,504,606,846,976 Bytes

Kilobyte KB 210 Bytes 1,024 Bytes

Megabyte MB 210 KB 1,024 KB

Gigabyte GB 210 MB 1,024 MB

Terabyte TB 210 GB 1,024 GB

Petabyte PB 210 TB 1,024 TB

Exabyte EB 210 PB 1,024 PB

ITDR2102 – Computer Organization 10


ASCII character code
• How does the computer know that 'A' is 'A' and not
'a' or '3' or anything else?
• Actually, it doesn’t — there is no inherent
difference between the patterns for 65 and ‘A’ (or
even ‘A’, but that is another story).
• As with any other symbols, it depends on
interpretation and context.

ITDR2102 – Computer Organization 11


ASCII character code
• ASCII: American Standard Code for Information Interchange.
• Based on 7 bits (Why?).
• For example:
• A 100 0001 0 011 1001
• a 110 0001 ! 001 0001
• Also defines non-printing characters such as line feed, form
feed, horizontal tab, etc.
• There are 128 (27) possible characters, stored in memory as a
byte with the 8th bit usually 0.
• Characters can be compared for sorting purposes based on
the numeric value of the code. Often called the collating
sequence.
• Covers English language letters only.

ITDR2102 – Computer Organization 12


ASCII Table

ITDR2102 – Computer Organization 13


Other Character Codes
• BCD — Binary coded decimal.
• 6-bits + check bit.
• Used for some magnetic tapes.
• EBCDIC – Extended Binary Coded Decimal
Interchange Code.
• Used with large IBM computers.
• BAUDOT
• Paper tape code
• 80 column cards.
• 12-bit code. Many patterns were unused.

ITDR2102 – Computer Organization 14


But what about …?
• Other writing systems?
• Greek, Arabic, Chinese, Hebrew, . . .
• Graphics?
• astrology, Zingbats, international . . .
• Characters that represent ideas, concepts, and
phrases?

ITDR2102 – Computer Organization 15


Unicode
• Unicode was developed by The Unicode Consortium.
• Based on 16-bit code, so 65,535 possible characters.
• Defines codes for characters used in the major
languages written today.
• Scripts include:
• Latin, Greek, Cyrillic, Armenian, Hebrew, Arabic,
Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil,
Telugu, Kannada, Malayalam, Thai, Lao, Georgian,
Tibetan, Japanese Kana.
• Includes extensions to allow for millions of characters.
• Can handle composite characters such as those with
accent marks, dots, double dots, macrons, etc.

ITDR2102 – Computer Organization 16


Suggested Video

• Inside your computer – By Bettina Bair

• https://www.youtube.com/watch?v=AkFi90lZmXA

ITDR2102 – Computer Organization 17


A Bit of History

• Numeral – a single symbol that represents a quantity or


number.
• Number system – a way of assigning meaning to
combinations of numerals.
• Base 10 (denary) number system used by most cultures (10
fingers).
• Mayas, Celts, Aztecs – base 20.
• Sumerians and Babylonians – base 60.

ITDR2102 – Computer Organization 18


The Decimal System
• System based on decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to represent
numbers
• For example the number 83 means eight tens plus three:
83 = (8 * 10) + 3
• The number 4728 means four thousands, seven hundreds, two tens,
plus eight:
4728 = (4 * 1000) + (7 * 100) + (2 * 10) + 8
• The decimal system is said to have a base of 10. This means that
each digit in the number is multiplied by 10 raised to a power
corresponding to that digit’s position:
83 = (8 * 101) + (3 * 100)
4728 = (4 * 103) + (7 * 102) + (2 * 101) + (8 * 100)

ITDR2102 – Computer Organization 19


Decimal Fractions
• The same principle holds for decimal fractions, but negative powers
of 10 are used. Thus, the decimal fraction 0.256 stands for 2 tenths
plus 5 hundredths plus 6 thousandths:
0.256 = (2 * 10-1) + (5 * 10-2) + (6 * 10-3)

• A number with both an integer and fractional part has digits base to
both positive and negative powers of 10:
442.256=(4*102) + (4*101) + (2*100) + (2*10-1) + (5*10-2)+ (6*10-3)

• Most significant digit


• The leftmost digit (carries the highest value)
• Least significant digit
• The rightmost digit

ITDR2102 – Computer Organization 20


Numbers (continued)

• There are other number systems (bases).

• The 'value' of a number is determined by positional notation.

• In general,

def.xyzb = d*b2 + e*b1 + f*b0 + x*b-1+ y*b-2+ z*b-3

where b is the base.

ITDR2102 – Computer Organization 21


The Binary System
• Only two digits, 1 and 0
• Represented to the base 2
• The digits 1 and 0 in binary notation have the same meaning
as in decimal notation:
02 = 010
12 = 110
• To represent larger numbers each digit in a binary number
has a value depending on its position:
102 = (1 * 21) + (0 * 20) = 210
112 = (1 * 21) + (1 * 20) = 310
1002 = (1 * 22) + (0 * 21) + (0 * 20) = 410
and so on. Again, fractional values are represented with
negative powers of the radix:
1001.1012 = 1*23 + 0*22 + 0*21 +1*20 +1*2-1 +0*2-2 +1*2-3 = 9.62510
ITDR2102 – Computer Organization 22
Converting Between Binary and Decimal
• Binary to decimal conversion:
• Multiply each binary digit by the appropriate power
of 2 and add the results.
• Example:
1001.1012 = 1*23 + 0*22 + 0*21 +1*20 +1*2-1 +0*2-2 +1*2-3 = 9.62510

• Decimal to binary conversion:


• Integer and fractional parts are handled separately
• The integer part: repeatedly divide by 2. Use the
remainders from bottom to top.
• The fraction part: repeatedly multiply by 2 until it
is zero or you get tired (run out of space). Use the
integer part from top to bottom.
• Example in the next slides.
ITDR2102 – Computer Organization 23
Decimal to Binary Conversion
Example
• Convert 38.6875 to binary.
• Dividend Quotient Remainder
38 19 0  LSB
19 9 1
9 4 1
4 2 0
2 1 0
1 0 1  MSB
• 3810 = 1001102

ITDR2102 – Computer Organization 24


Decimal to Binary Conversion
Example
• The integer part (38):
Dividend Quotient Remainder
38 19 0  LSB
19 9 1
9 4 1
4 2 0 3810 = 1001102
2 1 0
1 0 1  MSB

• The fraction part (0.6875):


Multiplicand Integer Fractional
Part Part
0.6875 1 .375  MSB
0.375 0 .750
0.75 1 .500
0.50 1 .000  LSB
0.687510 = 10112
• The whole number by combining the two parts: 38.687510 = 100110.10112

ITDR2102 – Computer Organization 25


Repeating & Irrational Numbers
• If the denominator has factors other than 2 or 5 it will
produce a recurring decimal fraction, e.g. 1/3 = 0.3333 …
• Irrational numbers, such as √2, and transcendental
numbers, such as p, also never terminate.
• Thus most decimal fractions will produce recurring binary
fractions.
• Truncate (or round) these to fit in available storage.

ITDR2102 – Computer Organization 26


Hexadecimal Notation
• Uses: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
• Takes 4 bits.
• To convert from binary, group the bits in fours.
• Each possible combination of four binary digits is given a
symbol, as follows:
0000 = 0 0100 = 4 1000 = 8 1100 = C
0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F

2C16 = (2 * 161) + (C * 160)


= (2 * 161) + (12 * 160)
= 4410

ITDR2102 – Computer Organization 27


Hexadecimal Notation

Reasons for using


hexadecimal notation are:

In most computers, binary It is extremely easy


It is more data occupy some multiple to convert
compact than of 4 bits, and hence some between binary
binary notation multiple of a single and hexadecimal
hexadecimal digit notation

ITDR2102 – Computer Organization 28


Hexadecimal Number System (continued)
0000 0 1000 8
0001 1 1001 9
0010 2 1010 A
0011 3 1011 B
0100 4 1100 C
0101 5 1101 D
0110 6 1110 E
0111 7 1111 F

100 1101 1001 1111  4D9F16

ITDR2102 – Computer Organization 29


Octal Number System

• A base 8 number system.


• Uses: 0, 1, 2, 3, 4, 5, 6, 7.
• Takes 3 bits.
• To convert from binary, group the bits in
threes.
000 0 100 4
001 1 101 5
010 2 110 6
011 3 111 7
ITDR2102 – Computer Organization 30
Other Conversions

• Conversions between decimal and octal or hexadecimal are


usually done via a binary representation, i.e. :

octal
decimal binary
hex

ITDR2102 – Computer Organization 31

You might also like