ICS-Lecture 3-4
ICS-Lecture 3-4
Computer Science
Example in base 10
What if we had a world in which ...
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
∗ 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
#include <stdio.h>
{ 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 ∗/
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.