0% found this document useful (0 votes)
18 views

ICS Lecture 3

This document provides an overview of binary numbers and computer programming concepts: - It discusses binary number system with base 2 and how numbers are represented in binary format with most and least significant bits. - It also introduces other number systems like hexadecimal and octal with their bases and examples. - Key computer programming concepts like algorithms, variables, data types, functions, control flow, syntax and libraries are explained at a high level. - The document demonstrates simple C code for printing "Hello World" and uses escape sequences like \n and \t.

Uploaded by

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

ICS Lecture 3

This document provides an overview of binary numbers and computer programming concepts: - It discusses binary number system with base 2 and how numbers are represented in binary format with most and least significant bits. - It also introduces other number systems like hexadecimal and octal with their bases and examples. - Key computer programming concepts like algorithms, variables, data types, functions, control flow, syntax and libraries are explained at a high level. - The document demonstrates simple C code for printing "Hello World" and uses escape sequences like \n and \t.

Uploaded by

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

ICS - Lecture 4

Slides are prepared from various sources 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 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 ! = 0612
! 111
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?

• Algorithm • Comment
• 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.
• In this course, you will learn both the art and science of
programming.
Introduction to C

C source code Compiler

This involves many micro-steps


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,
printf (“Hello world”); uses write system call

Statement terminator
}
Formatted output
More printing … (code and see)
#include <stdio.h>
void main()
{
printf ("Hello, World! ") ;
printf ("Hello \n World! \n") ;
}

\n character
Some more printing
#include <stdio.h>
void main()
{
printf ("Hello, World! \n") ;
printf ("Hello \n World! \n") ;
printf ("Hell\no \t World! \n") ;
}

\t character

You might also like