Programming Logic and Design: Mark Joniel M. Lopez, Cpe
Programming Logic and Design: Mark Joniel M. Lopez, Cpe
Programming Logic and Design: Mark Joniel M. Lopez, Cpe
LECTURE 1
MARK JONIEL M. LOPEZ,CpE
Number Systems
Why do we use 10 digits, anyway?
• Digit is derived from the Latin word for
“finger”
Decimal Numbering System
• Uses ten (10) as a base, also called base-
10 system.
• It uses ten digit symbols: 0, 1, 2, 3, 4, 5,
6, 7, 8, and 9.
• Each number position represents a
weighting factor (positional value system)
which is a power of the base ten. (1, 10,
100, 1000, etc.)
Decimal: Example
• 4175.8610 can be computed as:
Decimal Octal
-------- ------
0 0
1 1
7 7
8 10
9 11
Octal (cont.)
• For example to count in octal the digits
combine after reaching a count of 7
1,..7,10,11,12,…,17,20,21,…,75,76,77,100
• (127.4)8
= (1* 82) +(2 * 81) + (7 * 80) +
(4 * 8-1 )
= (87.5)10
• (4536)8
= (4x83) + (5x82) + (3x81) + (6x80)
= (1362)10
Summary: Octal
• In the octal system, a number with digits
XYZ can be written as:
• XYZ8
= (X x 82) + (Y x 81) + ( Z x 80)
Sixty fours Eights Ones
E 14
F 15
Hexadecimal (cont.)
• To count in hexadecimal: 0..F,10,11,…
19,1A,1B,..,1E,1F,20,
21,….99,9A,…,9F,A0,A1…..,FE,FF,100
• Try this…
—(BCF) 16
—(FA.CE) 16
Hexadecimal (cont.)
• XYZ16 = X x 162 + Y x 161 + Z x 160
256s 16s 1s
Base 10
2 1
2 0
Equivalent
0 0 0
0 1 1
1 0 2
1 1 3
Conversion of Integer from
Decimal to other Bases
• For each digit position:
1. Divide decimal number by the base.
2. The remainder is the lowest-order digit
3. Repeat first two steps until no divisor
remains.
Integer
Remainder Coefficient
Quotient
13/2 = 6 + ½ a0 = 1
6/2 = 3 + 0 a1 = 0
3/2 = 1 + ½ a2 = 1
1/2 = 0 + ½ a3 = 1
Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2
Integer Conversion:
• Try This:
—(53)10 = _____ 2
—(255)10 = _____ 8
—(2008)10 = _____ 16
—(100)10 = _____ 4
—(1024)10 = _____ 12
Conversion of Fractions from
Decimal to other Bases
• For each digit position:
1. Multiply decimal number by the base.
2. The integer is the highest-order digit
3. Repeat first two steps until fraction
becomes zero (or repeated/continuous).
—(0.8125)10= ______2
—(0.3125)10 = ______8
Hexadecimal to Binary Conversion
• Converting from Hex to Binary is easy:
• Example: (11100101010101.1101) 2
• Example: (17.5 ) 8
=(001 111 . 101) 2
Binary to Octal
• Just as simple, reverse to process
• Example: (11001010101.011101) 2