Number systems
| System | Base | Digits |
|---|---|---|
| Binary | 2 | 0, 1 |
| Octal | 8 | 0–7 |
| Decimal | 10 | 0–9 |
| Hexadecimal | 16 | 0–9, A–F (A = 10 … F = 15) |
Worked example
Convert decimal 13 to binary.
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 1 ÷ 2 = 0 remainder 1
- Read the remainders from bottom to top: 1101.
Binary to decimal: multiply each bit by its place value (1, 2, 4, 8, 16 … from the right) and add. 1101 = 8 + 4 + 0 + 1 = 13. Binary to hex: group bits in fours from the right; 1101 0110 = D6.
Logic gates and truth tables
A logic gate takes one or more inputs that are either 0 (false) or 1 (true) and gives one output. AND gives 1 only if all inputs are 1. OR gives 1 if any input is 1. NOT flips the input. NAND and NOR are AND and OR followed by NOT.
| A | B | A AND B | A OR B | A NAND B | A NOR B |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
Algorithms and flowcharts
An algorithm is a finite list of clear steps that solves a problem. A flowchart draws it with standard symbols: oval for start/stop, parallelogram for input/output, rectangle for a process, diamond for a decision.
C programming basics
Every C program starts running from main(). Variables must be declared with a type before use: int for whole numbers, float for decimals, char for a single character. printf() shows output; scanf() reads input; each statement ends with a semicolon.
if (n % 2 == 0) printf("Even"); else printf("Odd");
The flowchart above, in C
| Loop | Use it when |
|---|---|
| for | You know how many times to repeat |
| while | Repeat while a condition is true; may run zero times |
| do-while | Body must run at least once |
Key words
Test yourself
Build your own quiz: pick topics, number of questions and a time limit. It's marked for you, with the working for every answer.
7 questions available
Build a quizQuestions students ask
Is C programming hard for Matric?
No, if you practise. The exam asks short programs: if-else, loops and simple input/output. Type each textbook program yourself and change it a little to see what happens.
How do I convert decimal to hexadecimal fast?
Divide by 16 repeatedly and read the remainders bottom to top, writing 10–15 as A–F. Or convert to binary first and group the bits in fours.
Want one-to-one help?
A checked Computer tutor, at home in Islamabad or Rawalpindi or online. The first 30 minutes are free.
Find a Computer tutor