0% found this document useful (0 votes)
49 views59 pages

Chapter Two: Data Representation and Basics of Computer Architecture

This document discusses data representation in computers and number systems. It covers that computers use binary to represent all data and describes the binary, octal, decimal, and hexadecimal number systems. It also discusses how alphanumeric, numeric, and other data types are encoded and stored in memory. Basic binary arithmetic operations like addition, subtraction, multiplication, and division are also explained.

Uploaded by

mike
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views59 pages

Chapter Two: Data Representation and Basics of Computer Architecture

This document discusses data representation in computers and number systems. It covers that computers use binary to represent all data and describes the binary, octal, decimal, and hexadecimal number systems. It also discusses how alphanumeric, numeric, and other data types are encoded and stored in memory. Basic binary arithmetic operations like addition, subtraction, multiplication, and division are also explained.

Uploaded by

mike
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

Chapter Two

Data Representation and Basics of Computer architecture

04/01/2023 Natnael T. SWEG 2021 1


Data Representation
Computers use digital representation
 Based on a binary system (uses on/off states
to represent 2 digits).
 ALL data (no matter how complex) must be
represented in memory as binary digits (bits).

04/01/2023 Natnael T. SWEG 2021 2


Number systems and computers
• Computers store all data as binary digits, but
we may need to convert this to a number
system we are familiar with.
• Computer programs and data are often
represented (outside the computer) using
octal and hexadecimal number systems
because they are a short hand way of
representing binary numbers.

04/01/2023 Natnael T. SWEG 2021 3


Number Systems - Decimal
 The decimal system is a base-10 system.
 There are 10 distinct digits (0 to 9) to represent
any quantity.
 For an n-digit number, the value that each digit
represents depends on its weight or position.
 The weights are based on powers of 10.
 1024 = 1*103 + 0*102 + 2*101 + 4*100 = 1000 +
20 + 4

04/01/2023 Natnael T. SWEG 2021 4


Number Systems - Binary
• The binary system is a base-2 system.
• There are 2 distinct digits (0 and 1) to represent
any quantity.
• For an n-digit number, the value of a digit in
each column depends on its position.
• The weights are based on powers of 2.
• 10112 = 1*23 + 0*22 + 1*21 + 1*20 =8+2+1 =1110

04/01/2023 Natnael T. SWEG 2021 5


Number Systems - Octal
• Octal and hexadecimal systems provide a shorthand way
to deal with the long strings of 1’s and 0’s in binary.
• Octal is base-8 system using the digits 0 to 7.
• To convert to decimal, you can again use a column
weighted system 75128 = 7*83 + 5*82 + 1*81 + 2*80 =
391410
• An octal number can easily be converted to binary by
replacing each octal digit with the corresponding group of
3 binary digits
• 75128 = 1111010010102

04/01/2023 Natnael T. SWEG 2021 6


Number Systems - Hexadecimal
 Hexadecimal is a base-16 system.
 It contains the digits 0 to 9 and the letters A to
F (16 digit values).
 The letters A to F represent the unit values 10
to 15.
 To convert to decimal, use a weighted system
with powers of 16.

04/01/2023 Natnael T. SWEG 2021 7


Number Systems - Hexadecimal
• Conversion to binary is done the same way as
octal to binary conversions.
• This time though the binary digits are
organized into groups of 4.
• Conversion from binary to hexadecimal
involves breaking the bits into groups of 4 and
replacing them with the hexadecimal
equivalent.

04/01/2023 Natnael T. SWEG 2021 8


Example #1
Value of 2001 in Binary, Octal and Hexadecimal

04/01/2023 Natnael T. SWEG 2021 9


Example #2
Conversion: Binary -> Octal ->Hexadecimal

04/01/2023 Natnael T. SWEG 2021 10


Decimal to BaseN Conversions
• To convert from decimal to a different number
base such as Octal, Binary or Hexadecimal
involves repeated division by that number
base
• Keep dividing until the quotient is zero
• Use the remainders in reverse order as the
digits of the converted number

04/01/2023 Natnael T. SWEG 2021 11


Example #3
Decimal to Binary 1492 (decimal) = ??? (binary) Repeated Divide by 2

04/01/2023 Natnael T. SWEG 2021 12


BaseN to Decimal Conversions
• Multiply each digit by increasing powers of the
base value and add the terms
• Example: 101102 = ??? (decimal)

04/01/2023 Natnael T. SWEG 2021 13


Data Representation
• Computers store everything as binary digits. So,
how can we encode numbers, images, sound,
text??
• We need standard encoding systems for each
type of data.
• Some standards evolve from proprietary products
which became very popular.
• Other standards are created by official industry
bodies where none previously existed.
04/01/2023 Natnael T. SWEG 2021 14
Alphanumeric Data
• Alphanumeric data such as names and addresses are
represented by assigning a unique binary code or
sequence of bits to represent each character.
• As each character is entered from a keyboard (or
other input device) it is converted into a binary code.
• Character code sets contain two types of characters:
– Printable (normal characters)
– Non-printable. Characters used as control codes.
• CTRL G (beep)

04/01/2023 Natnael T. SWEG 2021 15


Alphanumeric Codes
 Characters are represented internally by these 8-bit binary
codes.
 An 8-bit memory word can thus store one character.
 A 16-bit memory word is usually divided into two 8-bit
segments or bytes.
 Each of which can store a single character. Similarly, a 32-bit
memory word can store four characters.
 Character strings of length greater than the number of bytes
in a word are stored in two or more consecutive words.
• There are 3 main coding methods in use:
• ASCII, EBCDIC ,Unicode .

04/01/2023 Natnael T. SWEG 2021 16


ASCII
(American Standard Code for Information Interchange)

 7-bit code (128 characters)


 Has an extended 8-bit version
 Used on PC’s and non-IBM mainframes
 Widely used to transfer data from one
computer to another

04/01/2023 Natnael T. SWEG 2021 17


ASCII character set (Sample)

04/01/2023 Natnael T. SWEG 2021 18


EBCDIC
(Extended Binary Coded Decimal Interchange Code).

• An 8-bit code (256 characters)


• Different collating sequence to ASCII
• Used on mainframe IBM machine
• Both ASCII and EBCDIC are 8 bit codes
inadequate for representing all international
characters
– Some European characters
– Most non-Alphabetic languages
e.g Mandarin, Kanji, Arabic, etc…
04/01/2023 Natnael T. SWEG 2021 19
Unicode
• New 16 bit standard - can represent 65,536 characters
• Of which 49,000 have been defined
– 6400 reserved for private use
– 10,000 for future expansions
• Incorporates ASCII-7
• Example - Java code:
char letter = ‘A’;
char word[ ] = ‘YES’;
• Stores the values using Unicode characters
• Java VM uses 2 bytes to store one Unicode character.

04/01/2023 Natnael T. SWEG 2021 20


Numeric Data
Need to perform computations
Need to represent only numbers
Using ASCII coded digits is very inefficient
Representation depends on nature of the data and
processing requirements
Display purposes only (no computations): CHAR
• PRINT 125.00
– Computation involving integers: INT
• COMPUTE 16 / 3 = 5
– Computation involving fractions: FLOAT
• COMPUTE 2.001001 * 3.012301 = 6.0276173133

04/01/2023 Natnael T. SWEG 2021 21


Representing Numeric Data
• Stored within the computer using one of several different
numeric representation systems
• Derived from the binary (base 2) number system.
• We can represent unsigned numbers from 0-255 just using 8 bits
• Or in general we can represent values from 0 to 2N -1 using N
bits.
• The maximum value is restricted by the number of bits available
(called Truncation or Overflow)
• However, most programming languages support manipulation of
signed and fractional numbers.
– How can these be represented in binary form?

04/01/2023 Natnael T. SWEG 2021 22


Representing Numeric Data
Range of Values 0 to 2N-1 in N bits

04/01/2023 Natnael T. SWEG 2021 23


Binary Arithmetic
Binary Addition

Addition in binary is precisely analogous to addition in


decimal.

Working from the write, if the sum of 2 digits produces a 2


digit result, the digit on the right is written down and the digit
on the left is added to the next column to the left.

04/01/2023 Natnael T. SWEG 2021 24


Example 1: Binary Addition

Example 2: Binary Addition


10101 and 11011

       1 1 1 1      Carry overs

       1 0 1 0 1

       1 1 0 1 1

    1 1 0 0 0 0
04/01/2023 Natnael T. SWEG 2021 25
Binary Subtraction

• Recall that in decimal subtraction one subtracts a decimal


digit from a smaller decimal digit by borrowing 1 from the
term on the left.
• Binary subtraction can be accomplished similarly. The
borrowed 1 and the 0 of the location involved combine to
form (10)2.
• Thus, if there is a digit on the left, 0 - 1 becomes 10 -1 = 1,
with a 1 borrowed from the left.

04/01/2023 Natnael T. SWEG 2021 26


Example 1: Binary Subtraction

Example 2: Binary Subtraction

04/01/2023 Natnael T. SWEG 2021 27


Binary Multiplication
• Binary multiplication is similar to decimal multiplication.
• It is simpler than decimal multiplication because only 0s and
1s are involved.
• There are four rules of binary multiplication.

04/01/2023 Natnael T. SWEG 2021 28


Binary Division
• Binary division is similar in procedure to decimal division.
• The placement of the binary point is exactly the same as the
placement of the decimal point in decimal division.

04/01/2023 Natnael T. SWEG 2021 29


Integer Representation
• UNSIGNED representing numbers from 0 upwards or
SIGNED to allow for negatives.
• In the computer we only have binary digits, so to
represent negative integers we need some sort of
convention.
• Four conventions in use for representing negative
integers are:
– Sign and Magnitude
– 1’s Complement
– 2’s Complement
– Excess 128
04/01/2023 Natnael T. SWEG 2021 30
Negative Integers – Sign and Magnitude
 Simplest form of representation
 Stores positive and negative values by dividing the “n” total
bits into two parts: 1 bit for the sign and n–1 bits for the value
which is a pure binary number
 Example:
– +6 in 8-bit representation is: 00000110
– -6 in 8-bit representation is: 10000110
 Disadvantages
– Arithmetic is difficult
– Two representations for zero
• 00000000
• 10000000

04/01/2023 Natnael T. SWEG 2021 31


Negative Integers – One’s (1’s) Complement

• Computers generally use a system called


“complementary representation” to store
negative integers.
• Two basic types - ones and twos complement,
of which 2’s complement is the most widely
used.
• Negative numbers begin with 1, positive with
0.

04/01/2023 Natnael T. SWEG 2021 32


Negative Integers – One’s (1’s) Complement

• To perform 1’s complement operation on a binary number, replace


1’s with 0’s and 0’s with 1’s (i.e Complement it!)
+6 represented by: 00000110
-6 represented by: 11111001
• Advantages: arithmetic is easier (cheaper/faster electronics)
• Fairly straightforward addition – Add any carry from the Most
Significant (left-most) Bit to Least Significant (right-most) Bit of the
result
• For subtraction – form 1’s complement of number to be subtracted
and then add
• Disadvantages : still two representations for zero 00000000 and
11111111 (in 8-bit representation)

04/01/2023 Natnael T. SWEG 2021 33


One’s Complement Example
• Case I: When the positive number has greater
magnitude.

Hence the required sum is + 0001.

04/01/2023 Natnael T. SWEG 2021 34


One’s Complement Example cont.
• Case II: When the negative number has
greater magnitude.

Hence the required sum is  – 0010.

04/01/2023 Natnael T. SWEG 2021 35


Negative Integers – Two’s (2’s) Complement

• To perform the 2’s complement operation on a binary


number
– Replace 1’s with 0’s and 0’s with 1’s (i.e. the one's
complement of the number)
– Add 1
+6 represented by: 00000110
-6 represented by: 11111010
• Advantages:
– Arithmetic is very straightforward
– End Around Carry is ignored
• only one representation for zero (00000000)
04/01/2023 Natnael T. SWEG 2021 36
Negative Integers – Two’s (2’s) Complement

• Two’s Complement
–To convert an integer to 2’s complement
 Take the binary form of the number
00000110 (6 as an 8-bit representation)
 Flip the bits: (Find 1’s Complement)
11111001
 Add 1 11111001 +1 = 11111010 (2’s complement of 6)
 Justification of representation: 6+(-6)=0?
00000110 (6)
+11111010 (2’s complement of 6)
100000000 (0)

04/01/2023 Natnael T. SWEG 2021 37


Negative Integers – Two’s (2’s) Complement

Properties of Two’s Complement


–The 2’s comp of a 2’s comp is the original number
00000110 (6)
11111010 (2’s comp of 6)
00000101
+1
00000110 (2’s comp of 2’s comp of 6)
–The sign of a number is given by its MSB
The bit patterns:
• 00000000 represents zero
• 0nnnnnnn represents positive numbers
• 1nnnnnnn represents negative number

04/01/2023 Natnael T. SWEG 2021 38


Negative Integers – Two’s (2’s) Complement

•Addition
–Addition is performed by adding corresponding bits
00000111 ( 7)
+00000101 (+5)
00001100 (12)
•Subtraction –Subtraction is performed by adding the 2’s
complement
–Ignore End-Around-Carry
00001100 (12)
+11111011 (-5)
100000111 ( 7)

04/01/2023 Natnael T. SWEG 2021 39


Negative Integers – Two’s (2’s) Complement

•Interpretation of Negative Results


00000101 ( 5)
+11110100 (-12)
11111001 ( )
–Result is negative
MSB of result is 1 so it is a negative number in 2’s complement
form
–Negative what?
Take the 2’s comp of the result to find out since the 2’s comp of a
2’s comp is the original number
–Negative 7 the 2’s complement of 11111001 is 00000111 or 710

04/01/2023 Natnael T. SWEG 2021 40


Integer Overflow
• Problem: A result of an artihematic operation that is too big to
be represented in number of bits available. This is called
overflow.
• Overflow can occur whether or not there is a carry

Example:

04/01/2023 Natnael T. SWEG 2021 41


Basics of digital logic gates and Boolean algebra

• Binary (Boolean) Logic deals with binary


variables and binary logic functions has two
discrete values
0 -> False, Open
1 -> True, Close
• Three basic logical operations
AND (.); OR (+); NOT (‘)

04/01/2023 Natnael T. SWEG 2021 42


Logic Gates & Truth Tables

04/01/2023 Natnael T. SWEG 2021 43


04/01/2023 Natnael T. SWEG 2021 44
Other Logic Gates – NAND Gate
• 2-input NAND (NOT-AND operation)
• Can have any # of inputs

04/01/2023 Natnael T. SWEG 2021 45


Other Logic Gates – NOR Gate „
• 2-input NOR (NOT-OR operation)
• Can have any # of inputs

04/01/2023 Natnael T. SWEG 2021 46


Other Logic Gates – XOR Gate
• 2-input XOR Output is 1 if any input is one and
the other input is 0
• Can have any # of inputs

04/01/2023 Natnael T. SWEG 2021 47


Other Logic Gates – XNOR Gate

04/01/2023 Natnael T. SWEG 2021 48


Introduction to computer organization and
Architecture.
Why study computer organization and
architecture?
– Design better programs, including system software such as
compilers, operating systems, and device drivers.
– Optimize program behavior.
– Evaluate (benchmark) computer system performance.
– Understand time, space, and price tradeoffs.

04/01/2023 Natnael T. SWEG 2021 49


• Computer organization
– physical aspects of computer systems.
– E.g., circuit design, control signals, memory types.
– How does a computer work?
• Computer architecture
– Logical aspects of system as seen by the
programmer.
– E.g., instruction sets, instruction formats, data
types, addressing modes.
– How do I design a computer?

04/01/2023 Natnael T. SWEG 2021 50


• At the most basic level, a computer is a device
consisting of three pieces:
– A processor to interpret and execute programs
– A memory to store both data and programs
– A mechanism for transferring data to and from the
outside world.

04/01/2023 Natnael T. SWEG 2021 51


The Computer Level Hierarchy Level
Hierarchy
• Writing complex programs requires a “divide and
conquer” approach, where each program module
solves a smaller problem.

• Complex computer systems employ a similar


technique through a series of virtual machine
layers.

04/01/2023 Natnael T. SWEG 2021 52


…. Cont
• Each virtual machine layer is an abstraction of
the level below it.
• The machines at each level execute their own
particular instructions, calling upon machines at
lower levels to perform tasks as required.
• Computer circuits ultimately carry out the work.

04/01/2023 Natnael T. SWEG 2021 53


04/01/2023 Natnael T. SWEG 2021 54
…….cont
• Level 6: The User Level
– Program execution and user interface level.
– The level with which we are most familiar.

• Level 5: High-Level Language Level


– The level with which we interact when we write
programs in languages such as C, Pascal, Lisp, and
Java.

04/01/2023 Natnael T. SWEG 2021 55


……cont
• Level 4: Assembly Language Level
– Acts upon assembly language produced from Level
5, as well as instructions programmed directly at
this level.
• Level 3: System Software Level
– Controls executing processes on the system.
– Protects system resources.
– Assembly language instructions often pass
through Level 3 without modification.

04/01/2023 Natnael T. SWEG 2021 56


……cont
• Level 2: Machine Level
– Also known as the Instruction Set
Architecture (ISA) Level.
– Consists of instructions that are particular
to the architecture of the machine.
– Programs written in machine language need
no compilers, interpreters, or assemblers.

04/01/2023 Natnael T. SWEG 2021 57


……cont.
• Level 1: Control Level
– A control unit decodes and executes instructions
and moves data through the system.
– Control units can be micro-programmed or
hardwired.
– A micro-program is a program written in a low-
level language that is implemented by the
hardware.
– Hardwired control units consist of hardware that
directly executes machine instructions.
04/01/2023 Lalise D. SWEG 2021 58
…….cont
• Level 0: Digital Logic Level
– This level is where we find digital circuits (the
chips).
– Digital circuits consist of gates and wires.
– These components implement the mathematical
logic of all other levels.

04/01/2023 Natnael T. SWEG 2021 59

You might also like