Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Chapter 1-Programming Basics

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

Chapter 1-Programming Basics

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

PROGRAMMING

BASICS

Prepared by: Ms. Jullie Ann M. Ocampo


Programming Languages
1. Machine Language
▪ The fundamental language of the
computer’s processor, also called Low
Level Language.
▪ All programs are converted into machine
language before they can be executed.
▪ Consists of combination of 0’s and 1’s
that represent high and low electrical
voltage.

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.

3. High Level Language


▪ Computer (programming)
languages that are easier to learn.
▪ Uses English like statements.
▪ Examples are C ++, Visual Basic,
Pascal, Fortran and etc.
3
Number System
COMMON NUMBER SYSTEM

System Base Symbols Used in computers?

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

Most significant digit Least significant digit

Hexadecimal: 1D63A7A

Most significant digit Least significant digit

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

• Also called the “Base 2 system”


• The binary number system is used to model
the series of electrical signals computers
use to represent information
• 0 represents the no voltage or an off state
• 1 represents the presence of voltage or an
on state
8
Number System
Octal Number System
• Also known as the Base 8 System
• Uses digits 0 - 7
• Readily converts to binary
• Groups of three (binary) digits can be used
to represent each octal digit
• Also uses multiplication and division
algorithms for conversion to and from base
10
9
Number System
Hexadecimal 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

001 = 1 100 = 4 111 = 7 001 010 = 12

010 = 2 101 = 5 001 000 = 10 001 011 = 13

13
Cont… Example

1010112 ===> Octal


101 011
5 3

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

Binary value would be 111011.

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

Step 1: Convert Octal to Binary


Step 2: Convert binary to Hexadecimal

21
Cont… Example
738 = ?16

22
Cont… Cont…

Hexadecimal value would be 3B16

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

Binary value would be 111111.

24
Number System Conversion
Hexadecimal ➔ Octal

Step 1: Convert Hexadecimal to Decimal


Step 2: Convert Decimal to Octal

27
Cont… Example
3F16 = ?8

Binary value would be 111111.

28

You might also like