Chapter 1-Programming Basics
Chapter 1-Programming Basics
BASICS
2
2. Assembly Language
Cont… ▪ A low level language that is similar
to machine language.
▪ Uses symbolic operation code to
represent the machine operation
code.
Decimal 10 0, 1, … 9 No
Binary 2 0, 1 Yes
Octal 8 0, 1, … 7 No
Hexa- 0, 1, … 9,
16 No
decimal A, B, … F
4
Number System
Significant Digits
Binary: 11101101
Hexadecimal: 1D63A7A
5
Number System
Illustration
Decimal Binary Octal Hexadecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6
Cont… Decimal Binary Octal Hexadecimal
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
7
Number System
Binary Number System
• Base 16 system
• Uses digits 0-9 &
letters A,B,C,D,E,F
• Groups of four bits
represent each
base 16 digit
10
Number System Conversion
Binary → Decimal
❑ Technique
▪ Multiply each bit by 2n, where n is the
“weight” of the bit
▪ The weight is the position of the bit,
starting from 0 on the right
▪ Add the results
11
Cont… Example
1010112 ===> 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
12
Number System Conversion
Binary ➔ Octal
• The easiest method for converting binary to
octal is to use a substitution code
• Each octal number converts to 3 binary digits
Substitution Code
000 = 0 011 = 3 110 = 6 001 001 = 11
13
Cont… Example
538
14
Number System Conversion
Binary ➔ Hexadecimal
• Same as Octal we will use substitution code
• Each hex number converts to 4 binary digits
15
Cont… Example
110100112 ===> Hexadecimal
1101 0011
D 3
D316
16
Number System Conversion
Decimal → Binary
❑ Technique
▪ Divide by two, keep track of the
remainder
▪ First remainder is bit 0 (LSB, least-
significant bit)
▪ Second remainder is bit 1
29
Cont… Example
12510 = ?2
remainder
2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
30
Number System Conversion
Decimal ➔ Octal
❑Technique
▪ Divide by 8
▪ Keep track of the remainder
31
Cont… Example
123410 = ?8
remainder
8 1234
8 154 2
8 19 2
8 2 3
2
123410 = 23228
32
Number System Conversion
Decimal ➔ Hexadecimal
❑Technique
▪ Divide by 16
▪ Keep track of the remainder
33
Cont… Example
123410 = ?16
remainder
16 1234
16 77 2
16 4 13
4
123410 = 4D216
34
Number System Conversion
Octal → Binary
❑ Technique
▪ Convert Octal values into Decimal
▪ Convert Decimal to Binary
17
Cont… Example
738 = ?2
18
Number System Conversion
Octal ➔ Decimal
❑Technique
▪ Multiply each bit by 8n, where n is the
“weight” of the bit
▪ The weight is the position of the bit, starting
from 0 on the right
▪ Add the results
19
Cont… Example
7248 ==> 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
20
Number System Conversion
Octal ➔ Hexadecimal
21
Cont… Example
738 = ?16
22
Cont… Cont…
22
Number System Conversion
Hexadecimal ➔ Decimal
❑Technique
▪ Multiply each bit by 16n, where n is the
“weight” of the bit
▪ The weight is the position of the bit, starting
from 0 on the right
▪ Add the results
25
Cont… Example
ABC16 =>
C x 160 = 12 x 1 = 12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
26
Number System Conversion
Hexadecimal → Binary
❑ Technique
▪ Convert the Hexadecimal into
Decimal
▪ Convert Decimal to Binary
23
Cont… Example
6316 = ?2
24
Number System Conversion
Hexadecimal ➔ Octal
27
Cont… Example
3F16 = ?8
28