100% found this document useful (1 vote)
41 views27 pages

CSE 203G: Introduction To C: Lecture - 2

1) The document discusses the basics of binary numbers, memory, and computer components like the CPU and hard disk. 2) It explains that computers use binary numbers represented by bits (either 0 or 1) to store data and instructions in memory and on the hard disk. 3) The memory is where programs and data are temporarily stored while the computer is on, while the hard disk permanently stores programs and data even when the computer is off.

Uploaded by

Anik Sazid Ahsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
41 views27 pages

CSE 203G: Introduction To C: Lecture - 2

1) The document discusses the basics of binary numbers, memory, and computer components like the CPU and hard disk. 2) It explains that computers use binary numbers represented by bits (either 0 or 1) to store data and instructions in memory and on the hard disk. 3) The memory is where programs and data are temporarily stored while the computer is on, while the hard disk permanently stores programs and data even when the computer is off.

Uploaded by

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

CSE 203G: Introduction to C

Lecture – 2

Course Teacher: Dr. Md Sadek Ferdous


Assistant Professor, CSE, SUST
E-mail: [email protected]
Outline
• Basic concepts (contd…)
• Binary numbers
• Memory
• Mode of operation
• Programming language
Inside computers
• Have you had the chance to look inside of your computer?

CPU
Hard disk

Memory
Computer

Memory Hard disk

Computer
• Computers (CPUs) utilise programs for data processing
• For this, it relies on two major components:
• Memory – Stores programs and data. Gets destroyed when the computer is
powered off
• Hard disk – stores programs/data permanently
Computer

Memory Hard disk

Computer

Keyboard Monitor Output


Input
devices
devices Mouse Printer
Point to ponder
• What is the most intelligent computer?
Point to ponder?
• What is the most intelligent computer?
• Our brilliant brains
Brain vs Computer

Feature Computer Our Brilliant Brain


Intelligence Dumb Intelligent
Speed of basic calculations Ultra-fast Slow
Can get tired Never After sometime
Can get bored Never Almost always

• Computers are ultra-fast and ultra-dumb!!


Binary number systems
• Uses only two symbols: 0 and 1 Dec Binary
0 0
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
Binary to decimal conversion

101011 è 1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20 = 43


(101011)2 = (43)10

111001 è 1x25 + 1x24 + 1x23 + 0x22 + 0x21 + 1x20 = 57


(111001)2 = (57)10

10100 è 1x24 + 0x23 + 1x22 + 0x21 + 0x20 = 20


(10100)2 = (20)10
Decimal to binary conversion
(15)10=>(1111)2
• Step 1: Divide the number by the “Base”
until the quotient becomes 0
• Step 2: Collect the remainder after each
step
• Finally: Trace the remainders in the reverse
direction
zeros and ones. These zeros and ones are called bits (binary digits). Each bit Fig.is1.2
represented by an electronic
device that is, in some sense, either “off’ (zero) or “on” (one).
Small computers have memories thatThe aresize
organized into 8-bit
of a computer’s memory multiples
is usually called
expressedbytes,
as some illustrated
asmultiple of 21° in Fig. bytes. This is
= 1024

1.2. Notice that the individual bits are numbered, beginning with 0 (for the rightmost bit) and extending to 7from 4 to 16
referred to as 1K. Modem small computers have memories whose sizes typically range

Bits & bytes


megabytes, where 1 megabyte (1M) is equivalent to 21° x 21° bytes, or 21° K = 1024K bytes.
(the leftmost bit). Normally, a single character (e.g., a letter, a single digit or a punctuation symbol) will
occupy one byte of memory. An instruction
EXAMPLE may 1.2 Theoccupy
memory of1,a personal
2 or 3computer
bytes.hasAa capacity
singleof numeric quantity
16M bytes. Thus, may
as many as 16 x 1024 x 1024 =
16,777,216 characters and/or instructions can be stored in the computer’s memory. If the entire memory is used to
occupy 1 to 8 bytes, depending on itsrepresent
precision (i.e., the number of significant figures) and its type (integer,
character data (which is actually quite unlikely), then over 200,000 names and addresses can be stored within the
floating-point, etc.). computer at any one time, assuming 80 characters for each name and address.
If the memory is used to represent numeric data rather than names and addresses, then more than 4 million individual

• Bit (Binary Digit) – a single 1 orbit0number: Large7 computers


numbers can be stored at any one time, assuming each numeric quantity requires 4 bytes of memory.

6 5 4 have 3 memories
2 1 0 that are organized into rather than bytes. Each word will consist
words

• Byte – 8 consecutive bits


of a relatively large number of bits-typically 32 or 36. The bit-wise organization of a 32-bit word is
l lleftmost
Im In
illustrated in Fig. 1.3. Notice that the bits are numbered, beginning with (for the rightmost bit) and extending
to 3 1 (the bit).
0

• 2 bytes = 16 bits One byte


• 4 bytes = 32 bits bitno.: 3 1 3 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1918 17 1615 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Fig. 1.2
• Max. integer that can represented One 32-bit word
• in 1 byte = 255 (=11111111)
The size of a computer’s memory is usually expressed as some multiple of 21° = 1024 bytes. This is
referred to as 1K. Modem small computers have memories whose sizesFig.typically 1.3
range from 4 to 16
• In 4 bytes = 4,294,967,295
megabytes, where 1(= 32 1’s)
megabyte (1M) is equivalent to 21° x 21° bytes, or 21° K = 1024K bytes.

• No. of integers that can1.2 be The represented inofashas


1 abyte of= 256 from (the integers 0, 1,byte).2,
Figure 1.4 shows the same 32-bit word organized into 4 consecutive bytes. The bytes are numbered in the
EXAMPLE memory of a personalsamecomputer
manner capacitybits,
the individual 16M
rangingbytes. Thus,
(for theas many
rightmost as 16to 31024
byte)
0 1024
(the leftmost x x =

3,….255) 16,777,216 characters and/or instructions can be stored in the computer’s memory. If the entire memory is used to (typically
The use a 32- or a 36-bit word permits one numeric quantity, or a small of characters
group 4
or to be represented within a single word of memory. Large computers commonly have several million
5),
represent character data (which is actually words
quite (Le.,
unlikely),
several then over 200,000
megawords) names and addresses can be stored within the
of memory.
computer at any one time, assuming 80 characters for each name and address.
• 1 word = 4 bytes, 1If KB (Kilo
the memory Bytes)
is used to represent= 1024
numeric bytes
data rather than names = and210addresses,
Bytes then more than 4 million individual
numbers can be stored at any one time, assuming each numeric quantity requires 4 bytes of memory.
• 1 MB (Mega Bytes) = 1024 (210) KB = 220 bytes, 1 GB (Giga Bytes) = 1024 MB
Large computers have memories that are organized into words rather than bytes. Each word will consist
of a relatively large number of bits-typically 32 or 36. The bit-wise organization of a 32-bit word is
illustrated in Fig. 1.3. Notice that the bits are numbered, beginning with 0 (for the rightmost bit) and extending
to 3 1 (the leftmost bit).
Memory
• CPUs are extremely fast
• To match its speed for faster processing, we must supply data at the
same speed if possible
• Remember, data is stored permanently in the hard disk
• Unfortunately, hard disks are quite slow
• Memory acts as an intermediary between the hard disk and the CPU
• The most common memory is RAM (Random Access Memory)
• Memory is much faster than hard disks, but still slower than the CPU
Memory
• The more memory your computer has, the more data it can store to
supply this data to the CPU
• You might ask, why not we have as much memory as hard disks?
• Hard disks are cheaper but memory is quite expensive!
• So we need to find a balance!
Memory
• Memory is
divided into
locations
• Each location has
a unique address
• Inside each
location we store
certain amount of
data, represented
with bits or its
other multiples
Computer: speed and reliability
• Because of its extremely high speed, a computer can carry out
calculations within minutes that might require many days, perhaps
even months or years, if carried out by hand
• The time required to carry out simple computational tasks, such as
adding two numbers, is usually expressed in terms of microseconds (1
µsec = 10-6 sec) or nanoseconds (1 nsec = 10-3 µsec = 10-9 sec)
• Thus, if a computer can add two numbers in 10 nanoseconds (typical
of a modern medium-speed computer), 100million (108) additions will
be carried out in one second
Computer: speed and reliability
• Computers are also extremely reliable
• They do not make mistakes
• The mistakes you see or reported on the news are due to
programming errors or data entry errors
• Mostly by human errors!
Modes of operations
• Two different modes:
• Batch mode and the interactive mode
• Each has its own advantages for certain types of problems
• In batch processing, a number of jobs (programs) are entered into the
computer, stored internally, and then processed sequentially, one by
one
• Examples:
• Programs to add two numbers by John
• Programs to subtract two numbers by Alice
• Programs to multiply two numbers by Bob
• John’s job -> Alice’s job -> Bob’s job
Batch processing
• Jobs are submitted to an operator
• Operator groups jobs based on a similarity
• Submit grouped jobs in batches
• This mode of operation is well-suited to jobs that require large
amounts of computer time or are physically lengthy
• However, a small job can be scheduled in a long queue waiting for its
turn!
Timesharing & Interactive processing
• Timesharing allows many different users to use a single computer
simultaneously
• Timesharing is best suited for processing relatively simple jobs that do
not require extensive data transmission or large amounts of computer
time

again appears, and the entire procedure is repeated. If the student types no, the mess

Goodbye

Timesharing & Interactive processing is displayed and the computation is terminated.


Shown below is a printed copy of the information displayed during a typical
described above. In this session, an approximate value of r = 5.6 was determi
information typed by the student is underlined.
• Interactive computing is a type of Radius = 7 5
computing environment that Area = 7 8 . 5 3 9 8

originated with commercial Do you wish t o r e p e a t t h e c a l c u l a t i o n ? ves

timesharing systems Radius = 7 6


Area = 113.097

• In an interactive computing Do you wish t o r e p e a t t h e c a l c u l a t i o n ? ves

environment, the user and the Radius = ? 5.6


Area = 98.5204

computer interact with each other Do you wish t o r e p e a t t h e c a l c u l a t i o n ? no


during the computational session Goodbye

Notice the manner in which the student and the computer appear to be conve
the student waits until he or she sees the calculated value of the area before decidi
calculation. If another calculation is initiated, the new value for the radius suppl
previously calculated results.

Programs designed for interactive computing environments are some


Computers
• CPU understands machine language
• Different strings of 0’s and 1’s only!!
• Hard to remember and use
• Instruction set of a CPU
• Mnemonic names for this strings
Computers
• CPU understands machine language ¨ Start
• Different strings of 0’s and 1’s only!! ¨ Read M
• Hard to remember and use ¨ Write M
• Instruction set of a CPU ¨ Load Data, M
• Mnemonic names for this strings ¨ Copy M1, M2
¨ Add M1, M2, M3
¨ Sub M1, M2, M3
¨ Compare M1, M2, M3
¨ Jump L
¨ J_Zero M, L
¨ Halt
Computers
• Instruction sets of different types of CPUs different
• Need to write different programs for computers with different types
of CPUs even to do the same thing
• Solution: High level languages (C, C++, Java,…)
• CPU neutral, one program for many
• Compiler to convert from high-level program to low level program
that CPU understands
Computers
Low-Level Program
High-Level Program
0: Start
1: Read 20
Variables x, y; 2: Read 21
Begin 3: Compare 20, 21, 22
Read (x); 4: J_Zero 22, 7
Read (y); 5: Write 20
If (x >y) then Write (x) 6: Jump 8
else Write (y); 7: Write 21
End. 8: Halt
Writing programs
• Step 1: Write the program in a high-level language (in your
case, C)
• Step 2: Compile the program using a C compiler
• Step 3: Run the program (ask the computer to execute it)
The lecture slides can be found in the following location!

You might also like