COMP1105 - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

COMP1105

Description:

Megabyte 220 =1,048,576 bytes. Gigabyte 230 ... 32 megabytes. 2. 1. 0. Memory. COMP1105 - Semester I 2005/6. 11. Bits ... 1 megabyte (M / MB) = 2^20 ... – PowerPoint PPT presentation

Number of Views:182
Avg rating:3.0/5.0
Slides: 37
Provided by: cmpla
Category:

less

Transcript and Presenter's Notes

Title: COMP1105


1
COMP1105
  • history
  • computer organization,
  • hardware and software
  • programming languages
  • including C!
  • computer memory
  • number systems
  • data representation
  • 1. Introduction to computers

2
Fundamentals
  • A computer is a device that can input and store
    a set of instructions (program) designed to
    perform a specific task, input and store (data),
    process the stored data according to the
    instructions, and produce output to be relayed to
    its user.
  • Computer Systems Properties
  • Purpose - Special, General
  • Mode - Batch processing, multiprogramming,
    time-sharing, personal, distributed, client
    server
  • Type - micro, mini, mainframe, super
  • Hardware - memory, CPU, I/O
  • Software - Operating system, system software,
    applications,

3
Programming languages
  • A programming language is an artificial and
    formal language that has a limited set of
    vocabulary consisting of a set of instructions
    and a set of precise grammar rules
  • Special purpose programming languages
    structured query language (SQL)
  • General programming languages
  • Machine language
  • Assembly language
  • High-level languages

4
Some Programs
  • Machine 0000000 1101001 0010011
    0001010 1111011 1010100 1010010
    1011101 0000100 1110111 1110111
    1010101 0001001 0011001 1111111 1010000
  • Assembly short hand for machine language
  • High-Level Language
  • sum firstValue secondValue

5
High-level languages
1950 1960 1970 1980 1990
Fortran
Lisp
Algol-60
Cobol
Simula
PL/1
Algol-68
Pascal
Prolog
C
ML
Smalltalk
Ada
Miranda
Object- Oriented languages
Functional languages
Imperative and concurrent languages
Logic languages
  • Dates and ancestry of major programming
    languages, Watt 1990

6
Compilation
  • Interpretation Compilation

Source program
source program
Compiler
lexical analyser
Target program
input
output
syntax analyser
semantic analyser
efficient, multiple phases
error handler
symbol-table manager
intermediate code generator
Source program
output
Interpreter
code optimiser
input
slower, single phase
code generator
target program
7
The C Environment
  • C is a compiled language

C Source Program
Your Editor
C Object File
Preprocessed C Source Program
Executable File
Linker
C Compiler
Preprocessor
8
Memory
  • is where programs and data are stored
  • it can be regarded as a sequence of cells
  • frequently referred to as RAM (Random Access
    Memory).
  • Other types of memory
  • ROM (Read Only Memory)
  • DRAM (Dynamic RAM)
  • SRAM (Static RAM)
  • PROM
  • EPROM
  • Cache memory
  • Mass storage -Floppy disks, hard disks, optical
    disks, flash disks, tapes
  • Floppy capacity 1.44 Mb (equivalent to 350 A4
    text pages)
  • CD-ROM 600 MB (150,000 A4 text pages)
  • DVD-ROM 8.4 Gb (2,000,000 A4 text pages)

9
Bits bytes
  • Bit (Binary digIT) smallest unit
  • Kilobit 1,024 bits or 1000 bits
  • Megabit 1,024 kilobits or 1,000,000 bits
  • Byte (Binary Term) 8 bits
  • Kilobyte 210 1,024 bytes or 1000 bytes
  • Megabyte 220 1,048,576 bytes
  • Gigabyte 230 1,073,741,824 bytes
  • Terabyte 240 1,099,511,627,776 bytes (1
    trillion)
  • Petabyte 250 1,125,899,906,842,624 bytes or
    1,024 terabytes
  • Exabyte 260 1,152,921,504,606,846,976 bytes or
    1,024 petabytes
  • Zettabyte 270 1,024 exabytes
  • Yottabyte 280 1,024 zettabytes
  • Data transfer is measured in Bps, Kbps, Mbps,
    Gbps,

10
Computer memory - Addresses
Memory
0
1
2
  • Each memory location has a unique address
  • A memory address is a sequential number starting
    at 0
  • A bit (binary digit) is a 1 or 0 representing
    an on or off
    state of electricity
  • 8 bits represent a byte (character)




32 megabytes
Least significant or Low-order bit
Most significant or High-order bit
11
Bits Bytes The Metric System
  • When used to describe data transfer rates, bits
    and bytes are calculated as
  • 1 MB 1,000,000 bits/bytes
  • 1 kb 1,000 bits/bytes
  • 1 bit/byte
  • Their exact value is as follow
  • 1 byte 8 bits
  • 1 kilobyte (K / KB) 210 bytes 1,024 bytes
  • 1 megabyte (M / MB) 220 bytes 1,048,576
    bytes
  • 1 gigabyte (G / GB) 230 bytes 1,073,741,824
    bytes
  • 1 terabyte (T / TB) 240 bytes
    1,099,511,627,776 bytes
  • 1 petabyte (P / PB) 250 bytes
    1,125,899,906,842,624 bytes
  • 1 exabyte (E / EB) 260 bytes
    1,152,921,504,606,846,976 bytes

12
Base Systems
13
Number Systems
14
Positional property of numbering system
  • Each position in which a digit is written has a
    different positional or weighted value

15
Conversion Binary to Decimal
  • multiply each digit by its weighted position
  • add weighted values together
  • Example 1 (Whole Binary) 1100 10102
  • 127 1 26 0 25 0 24 1 23 0 22
    1 21 0 20
  • 128 64 0 0 8 0 2 0 20210
  • Example 2 (Decimal Binary) 0.10112
  • 1 2-1 0 2-2 1 2-3 1 2-4
  • 1 0.5 0 0.25 1 0.125 1 0.0625
    0.687510

16
Conversion Decimal to Binary
  • Method 1 Repeated Division by 2
  • divide decimal number by 2, the remainder is a
    binary digit and the process continues (by
    dividing the quotient by 2) until quotient
    becomes 0
  • begin at the least significant digit (right) and
    each new digit is written to more significant
    digit (the left) of the previous digit
  • Example 166

17
Conversion Decimal to Binary
  • Method 2 The subtraction Method
  • For this method, start with a weighted position
    value greater that the number.
  • If the number is greater than the weighted
    position for the digit, write down a 1 and
    subtract the weighted position value.
  • If the number is less than the weighted position
    for the digit, write down a 0 and subtract 0.
  • This process is continued until the result is 0.
  • Example 166

18
Binary, Octal and Hexadecimal
  • From binary
  • to octal split binary number into groups of 3
    digits and convert each group to corresponding
    octal
  • to hexadecimal split binary number into groups
    of 4
  • consider 1000110100012
  • Octal equivalent 43218
  • Hexadecimal equivalent 8D116

19
Binary, Octal and Hexadecimal
  • To binary
  • Reverse the process rewrite these groups as
    their equivalent octal or hexadecimal
  • 1000110100012

43218
  • 8D116

20
Decimal Conversions
  • From decimal to basen (n2,8,16)
  • Repeated division by n
  • Divide number by n,
  • First remainder becomes right-most digit in basen
    number
  • Divide quotient by n, the new remainder goes to
    the left of the last digit entered
  • Repeat steps (1,2 and 3) until quotient0
  • From basen to decimal
  • Multiply each digit in basen number by its
    positional values (weighted value)

21
Fractions
  • Repeat steps until either a zero value is
    obtained for the fractional part or the required
    number of significant digits is obtained.
  • Example
  • Convert 0.6251010 to base2
  • 0.625
  • x 2
  • 1.250 in binary
  • x 2 0.1012
  • 0.500
  • x 2
  • 1.000
  • decimal fractions to basen
  • Multiply the decimal fraction by n and place the
    integral part of the product as a basen digit in
    the result
  • The fractional part of the product is now
    multiplied by n.
  • The integral part of the new product is placed as
    basen digit to the right of the last digit in the
    result.

22
Fractions basen fractions to decimal
  • Decimal fractions can be represented as follows
  • 278.3210 2 x 102 7 x 101 8 x 100 3 x 10-1
    2 x 10-2
  • 200 70 8 0.3 0.02
  • 278.3210
  • Similarly, binary fraction can be represented as
  • 1010.1012 1 x 23 0 x 22 1 x 21 0 x 20
    1 x 2-1 0 x 2-2 1 x 2-3
  • 8 0 2 0 0.5 0 0.125
  • 10.62510

23
Arithmetic Unsigned integers
  • The larger the magnitude of the number, the
    greater the number of bits required in the binary
    representation.
  • The smallest number that can be represented is 0
  • The largest is 2n - 1, where n is the number of
    bits.

24
Signed integers sign magnitude
All 3 The leftmost bit is reserved to represent
the sign of the integer. 0 indicates a positive
number and 1 indicates a negative number.
  • sign and magnitude
  • 30 00011110
  • -30 10011110
  • The range of integers that can be stored in
    sign-magnitude is
  • -2n-1 - 1 to 2n-1 1
  • Problem Simple but requires number validation
    before arithmetic.
  • ones complement
  • twos complement

25
Signed integers 1s Complement
  • Leftmost bit is initially set to zero.
  • Absolute value of number (binary format) occupies
    the remaining bit places
  • For a negative number ALL the bits are then
    complemented (i.e. reverse). Note that this will
    make the sign bit 1 as it should be.
  • The 1s complement representation of 30 and 30
    are
  • 30 00011110
  • -30 11100001
  • Problem 0 and 0 are represented differently
    even though they are the same algebraically!
    This causes problems when doing tests on
    arithmetic results.
  • computers now use a variation of 1s complement
    (called 2s complement) that eliminates the
    problem.

26
Signed integers 2s Complement
  • Positive numbers are treated as in ones
    complement.
  • Negative numbers representation obtained by
    adding 1 to ones complement representation.
  • 1. Start with the absolute value in binary
  • 2. Complement all the bits
  • 3. Add 1 to the result
  • The 8-bit twos complement of representation -30
    is
  • Start 00011110
  • Complement 30 11100001
  • Add 1 1
  • -30 11100010

27
Addition in 2s Complement
  • using n bits, the range of
  • integers that can be stored
  • in twos complement is
  • -2n-1 to 2n-1 1
  • 4-bits - we can have 16
  • different binary patterns
  • 00002 ? 11112
  • positive integers
  • 0101 (5)
  • 0010 (2)
  • 01112 (7)
  • negative integers
  • convert integers into 2s complement
  • add as normal
  • if result is longer than 4 bits, truncate
    leftmost digit
  • obtain 2s complement
  • add sign bit

28
Subtraction in 2s Complement
  • add 2s complement of number
  • 0001 1000 (24) 1110 1000 (-24)
  • 1101 1011 (-37) 1101 1011 (-37)
  • 1111 0011 (-13) 11100 0011 carry
    ignored

29
Binary Coded Decimal
  • uses 4 bits to represent each decimal digit
  • Hexadecimals A-F are unused in BCD, example
  • A byte can represent 256 numbers using B, whereas
    only 100 numbers (0-99) can be coded in BCD
  • BCD calculations
  • Perform B arithmetic on numbers and convert to
    BCD
  • Example To store 378,
  • Obtain binary equivalent of 3, 7, and 8
    respectively.
  • 0011 0111 1000

30
Overflow Errors
  • 4-bit 2s complement range of values is 7 to 0
    to -8
  • ? 5 0101
  • 5 0101
  • 10 1010
  • but 1010 is negative, so 2s complement
  • 0110 6, add sign -6
  • 10 is out of range Overflow
  • overflow is detected
  • signs of operands are same, and sign of answer
    different
  • or, convert to decimal to validate answer
  • To solve this Allow more bits!

31
Floating points
  • Exponents
  • Short hand for multiplication (5)(5) 52,
    (5)(5)(5) 53
  • Dealing with numbers we prefer "27" rather than
    "33".  But with variables, we need the exponents,
    because we'd rather deal with "x6" than with
    xxxxxx"
  • Simplify (x3)(x4)
  • (x3)(x4) (xxx)(xxxxx) xxxxx xx
    x7 x(34)
  • we cannot simplify (x4)(y3) (x4)(y3) xxxx
    yyy (x4)(y3)
  • For very large or very small numbers it is
    simpler to use "scientific notation"
  • 124 (1.24)(100)  1.24 102
  • 0.000 000 000 043 6 (4.36)(10)-11

32
Floating points
  • Real numbers are defined as having both an
    integer and a fractional part.
  • Real numbers are represented within computers in
    scientific notation.
  • i.e. m x 10p
  • where m (the mantissa) - between 0 and 1
  • and p (the exponent) is an integer

33
Floating points Excess notation
  • Excess 2n-1 or biased
  • n Number of bits available
  • A signed integer N is represented by 2n-1 N.
    Each representation is thus 2n-1 excess in the
    value it represents.
  • The binary representation of 2n-1 is a 1 followed
    by n-1 zeros.
  • Example 8-bit representation of -7210 in excess
    2n-1 system.
  • Solution N -72 n 8
  • -72 is represented by -72 28-1
  • i.e. -72 128 5610 00111000
  • Hence -7210 00111000 in biased form

34
Floating points
  • 5.7510 101.112 how 5.75 or 143.5 represented?
  • convert decimal to Binary
  • write binary in normalized scientific notation
  • mantissa base exponent
  • normalize means
  • move binary point (radix) to the left of the most
    significant digit
  • adjust values of exponent so value of number is
    unchanged
  • 101.112 is written as
  • 101.11 20
  • 10.111 21
  • 1.0111 22
  • .10111 2 3
  • store normalised binary f x rp

35
Floating points
.10111 2 3
1
1
0
0
0
0
0
0
0
0
1
1
1
0
1
0
Mantissa (10 bits)
sign bit
exponent (6 bits)
36
Behind the Scenes How Binary, Hexadecimal and
Memory Addressing relates to C
  • Signed integer holds a different range of numbers
    than an unsigned
  • Unsigned integers range from 0 to 65535
  • Signed integers range from 32768 to 32767
  • C storage of characters ASCII Table
  • char c 65 // Puts the ASCII letter A in c
  • int ci A // Puts the number 65 in ci
  • Hexadecimal notation is efficient for describing
    memory locations and values, where is data
    value112 stored?
    1111 1111 1011 0101 ? In Decimal? 65461
  • System programming with C
  • Better interface with Assembly language programs

89
-3
45
66
23
48
1
112
456
-20
56
FFAE FFAF FFB0 FFB1 FFB2 FFB3 FFB4
FFB5 FFB6 FFB7 FFB8
Write a Comment
User Comments (0)
About PowerShow.com