0% found this document useful (0 votes)
6 views31 pages

ICS-Lecture 3-4

The document provides an introduction to computer science, focusing on number systems such as binary, hexadecimal, and octal, as well as the basics of programming languages, particularly C. It covers the history of C, its applications, and essential programming concepts like comments, functions, and the structure of a C program. Additionally, it emphasizes the importance of programming in enabling computers to perform various tasks.

Uploaded by

Vikas Choudhary
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
0% found this document useful (0 votes)
6 views31 pages

ICS-Lecture 3-4

The document provides an introduction to computer science, focusing on number systems such as binary, hexadecimal, and octal, as well as the basics of programming languages, particularly C. It covers the history of C, its applications, and essential programming concepts like comments, functions, and the structure of a C program. Additionally, it emphasizes the importance of programming in enabling computers to perform various tasks.

Uploaded by

Vikas Choudhary
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/ 31

CSL1010: Introduction to

Computer Science

Slides are prepared from multiple resources on the web.


Fundamentals: Binary Numbers
Indian System

Bakshali numerals, 7th century AD

Uses the decimal place value system

5301 = 5 * 103 + 3 * 102 + 0 * 101 + 1*100

Example in base 10
What if we had a world in which ...

∗ People had only two fingers.


Representing Numbers

102310 = 1 * 103 + 0 * 102 + 2 * 101 + 3 * 100 Decimal

base
Binary
1710 = 1 * 24 + 0 * 23 + 0 * 22 + 0 * 21 + 1 * 20 = 100012

Base = 2
Binary Number System
∗ They would use a number system with base 23/2
∗ 11, 1
∗ 5, 1
∗ 2,1
∗ 1,0
∗ 1 10111
Binary Number System
∗ They would use a number system with
base 2.
Number in decimal Number in binary
5 101
100 1100100
500 111110100
1024 10000000000
MSB and LSB
∗ MSB (Most Significant Bit)  The leftmost bit
of a binary number. E.g., MSB of 1110 is 1

∗ LSB (Least Significant Bit)  The rightmost bit


of a binary number. E.g.,
LSB of 1110 is 0
Hexadecimal and Octal Numbers

∗ Hexadecimal numbers
∗ Base 16 numbers – 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
∗ Start with 0x

∗ Octal Numbers
∗ Base 8 numbers – 0,1,2,3,4,5,6,7
∗ Start with 0
Examples
Decimal Binary Octal Hexadecimal
9 1001 0 11 0x 9
12 1100 0 14 0x C
17 10001 0 21 0x 11
28 11100 0 34 0x 1C

⏟⏟⏟
Convert 110010111 to the octal format : 110 010 111 = 0612

⏟⏟⏟
Convert 111000101111 to the hex format : 1110 0010 1111 = 0xC2F
Bits and Bytes
∗ Computers do not understand natural human languages,
nor programming languages
∗ They only understand the language of bits
Bit 0 or 1

Byte 08 or
bits1

Word 40bytes
or 1

kiloByte 1024
0 or 1bytes

megaByte 1006 or
bytes
1
What is a programming language?
• Comment
• Algorithm
• Debugging
• Variable
• IDE: Integrated Development
• Data Type
Environment
• Function
• Operator
• Control Flow
• Statement
• Syntax
• Libraries
Programming – Why?
• Computers are used for many different purposes in many
different situations.
• But, how can they be so versatile?
• Answer: They can be programmed

• The ability for a computer to be programmed allows it to do


whatever their programs tell them what to do.
• A program is a set of instructions that tell a computer what to
do.
• A computer cannot do anything unless it has a program to tell it
what to do
Programming – What?
• Programs are used to operate the components of a computer,
solve problems or satisfy a want/need.
• How long will it take me to get home if I drive x miles per hour?
• I want to be able to tell my friends what I am doing right now.
• Computer Programming is both an Art and a Science
• Every aspect of a program must be carefully designed
• As an art, programming takes creativity and problem solving.
• There is often no one correct way to solve a problem.
• As a science, there are formal and proven methods to go
about creating a programming.
Introduction to C

C source code Compiler

This involves many micro-steps


Welcome to the world of C
• Dennis Ritchie – AT&T Bell Laboratories – 1972
• 16-bit DEC PDP-11 computer
• Widely used today •
• extends to newer system architectures
• efficiency/performance
• low-level access
Welcome to the world of C
• Evolved over the years:
• 1972 – C invented
• 1978 – The C Programming Language published; first specification of
language
• 1989 – C89 standard (known as ANSI C or Standard C)
• 1990 – ANSI C adopted by ISO, known as C90
• 1999 – C99 standard
• mostly backward-compatible
• 2007 – work on new C standard C1X
Welcome to the world of C
• Systems programming: Faster Code
• OSes, like Linux
• microcontrollers: automobiles and airplanes
• embedded processors: phones, portable electronics, etc.
• DSP processors: digital audio and TV systems
• Derivatives: C++, Objective C, C#
• Influenced: Java, Perl, Python (quite different)
Welcome to the world of C
• Handle with care.
• Always run in a debugger like gdb (more later. . . )
• Never run as root
• Never test untested code on the college servers
Welcome to the world of C …
• Before you start the program
• Have an environment - gcc compiler or C IDE
• Linux users - inbuilt gcc complier
• IDE: Eclipse, VC++, KDevelop, Xcode
Welcome to the world of C….

#include <stdio.h>

int main (void)


{
printf (“Hello world”);
}
Welcome to the world of C….

#include <stdio.h> Header file

int main (void) Usually the entry point of a c program

{ Library function,
uses write system call
printf (“Hello world”);
Statement terminator
}
Formatted output
Structure of a .c file
• /* Begin with comments about file contents */
Insert #include statements and preprocessor de nitions
Function prototypes and variable declarations
De ne main() function {
Function body
}
De ne other function
{
}
fi
fi
Comments
• Comments: /∗ this is a simple comment ∗/
• Can span multiple lines
/∗ This comment spans
multiple lines ∗/

• Completely ignored by compiler


• Can appear almost anywhere
/∗ hello.c −− our rst C program */
fi
Comments
• Comments: /∗ this is a simple comment ∗/
• Can span multiple lines
/∗ This comment spans
multiple lines ∗/ // is also used for commenting (c++ style)

• Completely ignored by compiler


• Can appear almost anywhere
/∗ hello.c −− our rst C program */
fi
The #include macro
• Header files: constants, functions, other declarations •
#include <stdio.h> – read the contents of the header file
stdio.h
• stdio.h: standard I/O functions for console, les
#include <stdio .h> /∗ basic I /O facilities ∗/
The #include macro
• Header files: constants, functions, other declarations • #include
<stdio.h> – read the contents of the header file
stdio.h
• stdio.h: standard I/O functions for console, les
#include <stdio.h> /∗ basic I /O facilities ∗/
stdio.h – part of the C Standard Library
other important header les: ctype.h, math.h, stdlib.h, string.h,
time.h

fi
More printing … (code and see)
#include <stdio.h>
int main()
{
printf ("Hello, World! ") ;
printf ("Hello \n World! \n") ;
}
\n character
Some more printing
#include <stdio.h>
Int main()
{
printf ("Hello, World! \n") ;
printf ("Hello \n World! \n") ;
printf ("Hell\no \t World! \n") ;
}
\t character
That’s all for today.

You might also like