Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

2 - ComputerOrganization - Data Rep

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

2 - ComputerOrganization - Data Rep

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 75

Computer Organization

Positional Number System


• Our decimal number system is known as a
positional number system, because the value
of the number depends on the position of the
digits.
• For example, the number 123 has a very
different value than the number 321, although
the same digits are used in both numbers.
Different Positional Number Systems

• Denary - A digit in base 10 ranges from 0 to 9.


• Binary - A digit in base 2 ranges from 0 to 1.
A digit in base 2 is also called a ‘bit’.
• Hexadecimal - A digit in Base 16 can range
from 0 to 15 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
• Octal - A digit in Base 8 can range from 0 to 7
• Generally, a digit in base R can range from 0
to R-1
Positional Number System – Denary (Base
10)
Positional values or Place values or weights
102 101 100 10-1 10-2 10-3

1 2 3 . 3 2 1

MSD Decimal LSD


point

The number is written as 123.32110


Positional Number System – Binary (Base 2)

22 21 20 2-1 2-2 2-3

1 0 1 . 0 1 1

MSB LSB

base point or radix

The number is written as 101.0112


What is Binary System?
• Binary generally represents 2 states – 0 or 1.
• Aim of binary system is to represent data in
these two states
• These two states are easily implemented as a
switch in a computer.
• 0 – OFF, FALSE
• 1 – ON, TRUE
• There are millions of switches in a computer to
switch between 0 and 1
Denary System concept
• Base 10 system.

100 = 1
101 = 10
102 = 100
103 = 1000
104 = 10000
• So a denary number 248 is expanded in Base 10
system as
2x102 + 4x101 + 8x100
Binary System concept
• Base 2 system
20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
25 = 32 and so on
• So a binary number 110 is expanded in base 2
system as
1x22 + 1x 21 + 0x20
How to convert a binary number to denary?

• Example 1
• Binary 1110
0 x 20 = 0
1 x 21 = 2
1 x 22 = 4
1 x 23 = 8
Total = 14
Equivalent Denary Number = 14
How to convert a binary number to denary?
• Example 2
• Binary 101101010
0 x 20 = 0
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
1 x 26 = 64
0 x 27 = 0
1 x 28 = 256
Total = 256 + 64 + 32 + 8 + 4 + 2 = 362
How to convert a binary number to denary?

• Example 3
• Binary 1011.011
1 x 2-3 = 1/8 = 0.125
1 x 2-2 = 1/4 = 0.25
0 x 2-1 = 0
1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
Total = 0.125+ 0.25 + 0+ 1+ 2+ 0+8 = 11.375
Equivalent Denary Number = 11.375
How to convert a denary number to binary?
– Method 1
• We follow trial and error method using the place values.
• This can be used for small numbers.
27 26 25 24 23 22 21 20 Denary
128 64 32 16 8 4 2 1 Number
1 1 1 7
1 1 0 6
1 1 1 0 14
1 0 1 0 0 20
1 0 0 0 1 1 0 70
1 1 0 1 0 1 1 107

Fill up the appropriate position and make the total equal to the required
denary number.
How to convert a denary number to binary?
– Method 2
• We also follow successive or repetitive division by 2.
• This is more methodical.
• Example
• Take a denary number 245.
2| 245
2| Quotient 122 – Remainder 1
2| Quotient 61 – Remainder 0
2| Quotient 30 – Remainder 1
2| Quotient 15 – Remainder 0
2| Quotient 7 – Remainder 1
2| Quotient 3 – Remainder 1
2| Quotient 1 – Remainder 1
2| Quotient 0 – Remainder 1

Stop when the Quotient becomes 0


Take the remainders bottom up.
How to convert a denary number to binary?
– Method 2
• This is more methodical.
• Example
• Take a denary number 245.33
• We also follow successive or repetitive division by 2 for the part before
the base point
• We follow successive multiplication by 2 for the part after the base point
0.33 x 2 = 0.66
0.66 x 2 = 1.32
0.32 x 2 = 0.64
0.64 x 2 = 1.28
0.28 x 2 = 0.52 and it goes on

245 in denary = 1111 0101.01010 in binary


Fact
• Everything should be stored as binary in the
computer.
• Which means everything should be converted
to numbers
– Music
– Video
– Text like Abcd,&*(@
– Pictures
• Digital data comprises of binary numbers
Byte
• A binary digit is known as bit
• 8 bits are referred to as a Byte
• 4 bits make a Nibble
• The byte is the smallest unit of memory.
• With one byte, not much data can be stored.
• Usually data occupies multiple bytes.
Memory Sizes
Memory Size Number of bits Denary Value
1 Kilobyte 210 bytes 1024 bytes
1 megabyte 220 = 1000 KB 1048576 bytes
1 gigabyte 230 = 1000 MB 1073741824 bytes
1 terabyte 240 = 1000 GB 1099511627776 bytes
1 petabyte 250 = 1000 TB 1125899906842624 bytes
1 exabyte 260
1 zettabyte 270
1 yottabyte 280
IEC convention (International
Electrotechnical Commission )
Metric System IEC convention
1 Kilobyte 1000 bytes 1 Kibibyte 1024 bytes

1 megabyte 1000000 bytes 1 mebibyte 1048576 bytes

1 gigabyte 1000000000 bytes 1 gibibyte 1073741824 bytes

1 terabyte 1000000000000 bytes 1 tebibyte 1099511627776 bytes


Hexadecimal
• It is similar to binary system.
• Base 16 system
• 16 different values are required to represent a digit
• 0 1 2 3 4 5 6 7 8 9 A B C D E F are used
• Where A = 10, B =11, C=12, D=13, E= 14, F=15
160 = 1
161 = 16
162 = 256
163 = 4096
164 = 65536
• Since 16 = 24 , each hex digit requires 4 binary digits
Denary Binary Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Why Hexadecimal System?
• What does a Base 16 number system have to do
with a machine that's based on zeros and ones?
• Long before programmers regularly used a
convenient method to handle large binary
numbers in either 3-bit (octal) or 4-bit
(hexadecimal) groupings.
• Ease of display – saving screen space and paper
• Conversion from hex to binary and vice versa is
easier
Converting from Binary to Hex
• Example
1111100001
• Start from right and split into 4 bits
11 1110 0001
0011 1110 0001
3 E 1
Converting from Hex to Binary
• Example 45A
4 5 A
0100 0101 1010
Equivalent Binary is 10001011010
• Example BF08
B F 0 8
1011 1111 0000 1000
Equivalent Binary is 1011111100001000
Converting hex numbers to denary
• Example 45A
• Can be expanded as
• 4x162 + 5x161 + Ax160 (A is 10)
• Which is
• 1024 + 80 + 10 = 1114
Converting denary numbers to hex –
Method 1
• Trial and Error method
4096 256 16 1
7 D 4 = 2004
(D is 13)
Converting denary numbers to hex –
Method 2
• Repetitive division method by 16
16| 2004
16| Quotient 125 – Remainder 4
16| Quotient 7 – Remainder 13
Quotient 0 – Remainder 7

• Stop when the Quotient becomes 0


• Take the remainders bottom up.
• 2004 in denary = 7D4 in hex
Hexadecimal - Memory dump
• Representing numbers stored in registers and
main memory as hexadecimal
• In reality, the computer is working with 1’s and
0’s.
• But for the software programmers, it is easy to
remember hex than binary numbers.
• That’s why the memory dump of the main
memory and registers shows hex numbers.
• It needs 4 Hex digits for a 16 bit register
• It needs 2 Hex digits for a 8 bit register
Use of Hexadecimal System – Memory
Dumps
• Much easier to work with B 5 A 4 1 A F C
• Than 1011 1001 1010 0100 0001 1010 1111 1100
• It is used when
– developing new software
– Tracing errors in programs
• The contents of memory need to be checked to
solve problems
• The memory contents are printed or displayed as it
is which is known as memory dump
• Far Left shows memory location
• The memory dump usually contains hex numbers
• The developer can look at the hex codes and figure out the errors
and the location at which it occurred.
• But it needs considerable knowledge of computer architecture to
interpret the results.
Use of Hexadecimal System - HTML
• Hyper Text Markup Language is used for writing and
developing web pages.
• HTML uses <tags>
• <font color=“#ff0000”> <body bgcolor=“00ff00”>
• They are represented as 6 digit hexadecimal number
• 3 pairs - the first two to represent red, next two for
green and the last two for blue which are the primary
colors
• The variation in their intensities gives different colours.
• # FF 80 00 represents ORANGE
• Each pair can have values in range 00 to FF (0 to 255)
• # FF 00 00 represents RED
• # 00 FF 00 represents GREEN
• # 00 00 FF represents BLUE
• # FF FF FF represents WHITE
• # 00 00 00 represents BLACK
• There are websites which give the HTML code for the colour needed.
Data representation in the computer
• Computer work with the binary number system, so
everything in them is represented in 1s and 0s.
• So, the data that we want to store in the computer
needs to be encoded in 1s and 0s.
• TEXT
• Text needs to be also transformed into 0s and 1s.
• To do this, a character set is used.
• A character set is a collection of characters and the
binary codes that represent them.
• Today, the most used character sets are ASCII and
Unicode.
Data representation in the computer
• ASCII: stands for American Standard Code for Information
Interchange. It uses 7 (later 8) bits to encode the characters,
so in total 28=256 different characters can be represented.
• Unicode: is a superset of ASCII. It was developed because
people realized that the 256 characters of ASCII are not
enough to satisfy our need for a suitable number of
characters. It used 16 bits to encode, 216 = 65536 different
characters can be represented. Now it uses 32 bits.
• Advantages
– Data corruption is eliminated
– The product can get support in many platforms, countries
– Cost savings
• UTF-8 (Variable length), UTF-16(Variable length), UTF-32(Fixed length) variants
are present
• Strings: representation of characters in a continuous bit
Data representation in the computer
• Integers: representation of numbers in computers.
(Whole numbers)
• Unsigned Integers
– Covers only positive numbers
– For example - 8 bits 28 = 256 (0 t0 255 can be represented)
• Signed Integers
– Covers both positive and negative numbers
– For example – 8 bits 28 = 256 ( -128 to + 127 can be
represented)
– Negatives can be represented by the two's complement
method.
Two’s complement
• How to find
– Take the binary for the positive equivalent
– Revert the bits and add 1 to the LSB
– MSB determines whether the number is positive
or negative
Two’s Complement
• Normal Binary form for Positive Number (True form)
• Two’s complement form for negative number
• It is calculated by adding 1 to 1’s complement.
• 1’s complement of 0110 = 1001
• 2’s complement of 0110 = 1
-------------------
1010
Binary addition rules are 0+0=0
0+1=1
1+0=1
1 + 1 = 10
1 + 1 + 1 = 11
Two’s complement Binary
0111
Decimal
+7
• Consider 4 bit word length 0110 +6
0101 +5
1. There is one unique 0 0100 +4
2. The 2’s complement of 0 is 0 0011 +3
3. The leftmost bit actually represents 0010 +2
whether a number is negative and 0001 +1
positive, 0 – positive, 1 – negative 0000 0
4. 2’s complement of a negative number is 1111 -1
positive number 1110 -2
1101 -3
1100 -4
1011 -5
1010 -6
1001 -7
1000 -8
Data representation in the computer
• Real Numbers:
• representation of fractions within the computer.
• Fixed point notation
– 7.5 in 6 bit binary with point between 2nd and 3rd bit - 0111.10
– Multiplication method for converting decimal values after point
– Advantage - fixed-point adheres to the same basic arithmetic principles as
integers, therefore, can take advantage of the general optimizations made to
the Arithmetic Logic Unit (ALU) of most microprocessors, and do not require
any additional libraries or any additional hardware logic.
– Disadvantage - fixed-point numbers can represent only a limited range of
values, so fixed-point numbers are susceptible to common numeric
computational inaccuracies.
– For example, the range of possible values in the 8.8 notation that can be
represented is +127.99609375 to -128.0.
– If you add 100 + 100, you exceed the valid range of the data type, which is
called overflow.
– In most cases, the values that overflow are saturated, or truncated, so that
the result is the largest representable number.
Data representation in the computer
• Floating point notation
– Number is converted to mantissa and exponent

– The sign bit is 0 if the number is positive and 1 if the


number is negative.
– The exponent is an 8-bit number that ranges in value
from -127 to 128 (for normalized form).
– The exponent is actually not the typical two's
complement representation because this makes
comparisons more difficult.
– Instead, the value is biased by adding 127 to the
Data representation in the computer
• Floating point notation
– Now look at how to encode 118.625 as a float.
– The number 118.625 is a positive number, so the sign bit is 0.
– To find the exponent and mantissa, first write the number in
binary, which is 1110110.101.
– Next, normalize the number to 1.110110101 x 26, which is
the binary equivalent of scientific notation.
– (There is a denormalized form also – with implicit leading
zero)
– The exponent is 6 and the mantissa is 1.110110101.
– The exponent must be biased, which is 6 + 127 = 133. The
binary representation of 133 is 10000101.
– Thus, the floating-point encoded value of 118.65 is 0100
0010 1111 0110 1010 0000 0000 0000.
Data representation in the computer
• Colours
– Red, Green and Blue are the primary colors
– All the other colors are generated by the varying intensity of these
three colors.
– Each primary color is represented by 8 bits giving 256 different
intensities.
– Each color is represented by 24 bits (8x3) giving 16.7 Million color
shades.
– Since representing each color by 24 bits is cumbersome, it is
converted to Hex numbers.

http://www3.ntu.edu.sg/home/ehchua/programming/java/
datarepresentation.html
Introduction

e rsta nd t h is  Understand this 


Und
d e v i c e t h at • Logic gates serve as the
• Gate - A a s ic
r m s a b building blocks to digital
perfo
on
operation logic circuits using
c t r i ca l si g nals combinational logic.
e le a re
- G a t e s
• Circuits p e r form
• Logic gates basically
e d to
combin ted
process signals which
co m p l i c a represent true or false or
more
tasks the equivalent i.e. ON or
OFF, 1 or 0
Introduction

• Basic Gates
• 1. NOT gate
• 2. AND gate
• 3. OR gate
• 4. NAND gate
• 5. NOR gate
• 6. XOR gate.
• Logic diagram - A graphical representation of a
circuit
– Each type of gate is represented by a specific
graphical symbol
• Truth table - A table showing all possible input
values and the associated output values
Symbols Used
NOT GATE
• A NOT gate accepts one input value and
produces one output value

• A NOT gate is sometimes referred to as an


inverter because it inverts the input value
AND GATE
• An AND gate accepts two or more input
signals
• If all the input values for an AND gate are 1,
the output is 1; otherwise, the output is 0
OR GATE
• If all the input values are 0, the output value is
0; otherwise, the output is 1
• If one of the input values is 1, the output is 1
NAND GATE
• The NAND gate is the opposite of the AND
gate
• AND - NOT combination
NOR GATE
• The NOR gate is the opposite of the OR gate
• OR - NOT combination
XOR GATE
• exclusive OR gate
• An XOR gate produces 0 if its two inputs are the
same, and a 1 otherwise
• The output is true only when the inputs are
opposite of each other
• When both input signals are 1, the OR gate
produces a 1 and the XOR produces a 0
• Logical Expression for XOR gate is A  B or A.B + A.B
Basic Theorems

• Fundamental laws
• If X ≠ 0 then X = 1
• If X ≠ 1 then X = 0
• OR Relations
– 0+0=0
– 0+1=1
– 1+0=1
– 1+1=1
• AND Relations
– 0.0=0
– 0.1=0
– 1.0=0
– 1.1=1
• Complement Rules
– 0=1
– 1=0
Basic Theorems
• 0+X=X
• 1+X=1
• 0.X=0
• 1.X=X
• X+X=X
• X.X=X
• X’’ = X
Basic Theorems – De Morgan’s Theorem

• (A + B)’ = A’ . B’
• (AB)’ = A’ + B’
• Principle – Break the line and change the sign
Universal Gates
• NOR & NAND gates are universal gates
• Because using NAND/NOR gates, we can form
the other logic gates
NAND as Universal Gate
NOT Gate

AND Gate

OR Gate
NAND as Universal Gate
NAND as Universal Gate
NOR as Universal Gate

NOT Gate

OR Gate

AND Gate
NOR as Universal Gate

NAND Gate from NOR Gates


NOR as Universal Gate
XOR Gate from NOR Gates
Combinations of logic gates
• It is possible to combine logic gates together
to produce more complex logic circuits.
• Factors to keep in mind
– Cost of the components
– Ease of fabrication in a chip & Time constraints
– Space available to accommodate the components
• Simplified design is preferred (Simplified logic
expression with less number of gates)
Producing the truth table from a given logic
network
• Consider the following logic network which
contains three inputs and three logic gates:
• Deduce S, Deduce T and finally X
Designing logic networks to solve a specific
problem and testing using
truth tables
• Consider the following problem:
• “If button A or button B are on and button C is
off then the alarm X goes on”
• We can convert this into logic gate
terminology (ON = 1 and OFF = 0):
• If (A = 1 OR B = 1) AND (C = NOT 1) then (X = 1)
Example
• A steel rolling mill is to be controlled by a logic network made up of AND, OR and NOT
gates only. The mill receives a stop signal (i.e. S = 1) depending on the following input
bits:

• A stop signal (S = 1) occurs when:


• Either Length, L > 100 meters and Velocity, V < 10 m/s
• Or Temperature, T < 1000 C and Velocity, V > 10 m/s

• Draw a logic network and truth table to show all the possible situations when the stop
signal could be received.
Example
• The first thing to do is to try and turn the question into a series of logic gates and
then the problem becomes much simplified.

• The first statement can be re-written as: (L = 1 AND V = NOT 1) since Length > 100
meters
• corresponds to a binary value of 1 and Velocity < 10 m/s corresponds to a binary
value of 0 (i.e. NOT 1).

• The second statement can be re-written as (T = NOT 1 AND V = 1) since


Temperature < 1000C
• corresponds to a binary value of 0 (i.e. NOT 1) and Velocity > 10 m/s corresponds
to a binary value of 1

• Both these statements are joined together by OR which gives us the logic
statement:

• if (L = 1 AND V = NOT 1) OR (T = NOT 1 AND V = 1) then S = 1

You might also like