CpE 112
PROGRAMMING LOGIC AND DESIGN
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:
=(4 x 103) + (1 * 102) + (7 * 101) + (5 * 100) +
(8 * 10-1) + (6 * 10-2)
• 7,392.42 is equal to:
= (7 * 103) + (3 * 102) + (9 * 101) + (2 * 100) +
(4 * 10-1) + (2 * 10-2)
Octal Numbering System
• A base-eight numbering system with eight
digits of 0,1,2,3,4,5,6,7.
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
• For two octal digits the largest number is
77 so the two octal digits end after at 77.
Octal (cont.)
• To find the decimal number equal to an
octal number:
• (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
32768 4096 512 64 8 1
…. 85 84 83 82 81 80
Hexadecimal Numbering System
• Has a base-16
• There are 16 digits in this system: 0, 1..9, and A,
B, C, D, E, F)
Hexadecimal Decimal
----------- -------
0 0
1 1
…….. ……
9 9
A 10
B 11
…….. ……
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
• For two hexadecimal digits the largest
number is FF so the two hexadecimal
digits end after at FF.
Hexadecimal (cont.)
• To find the decimal number equal to a
hexadecimal number:
• (B65F)16
= (11 * 163)+ (6 * 162)+ (5 * 161)+ (5 * 160)
= (46,687)10
• Try this…
—(BCF) 16
—(FA.CE) 16
Hexadecimal (cont.)
• XYZ16 = X x 162 + Y x 161 + Z x 160
256s 16s 1s
1048576 65536 4096 256 16 1
…. 165 164 163 162 161 160
Binary Numbering System
• Uses two (2) as a base, made of binary
digits (bits): 0 and 1; useful to represent
switch positions (open or closed).
• Leftmost bit position is called Most
Significant Bit (MSB).
• Right most bit position is called Least
Significant Bit (LSB).
Binary Numbering System
• Groups of eight bits are called a byte
—(11001001) 2
• Groups of four bits are called a nibble.
— (1101) 2
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.
• Example: (13)10 = _____ 2
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).
• Example: (0.625)10 = ____2
Integer Fraction Coefficient
0.625 x 2 = 1 + 0.25 a -1 = 1
0.250 x 2 = 0 + 0.50 a -2 = 0
0.500 x 2 = 1 + 0 a -3 = 1
Answer (0.625)10 = (0.a-1 a-2 a-3 )2 = (0.101)2
Conversion
• Try This…
—(0.8125)10= ______2
—(0.3125)10 = ______8
Hexadecimal to Binary Conversion
• Converting from Hex to Binary is easy:
• Every hex digit becomes 4 binary digits
• Example #1: (1AF5) 16
=(0001 1010 1111 0101) 2
• Example #2: (306.D)16
= ( 0011 0000 0110. 1101 )2
Binary to Hexadecimal Conversion
• Just as simple, reverse to process
• Example: (11100101010101.1101) 2
=(0011 1001 0101 0101 . 1101) 2
=(3955.D) 16
Octal to Binary
• Converting from Octal to Binary is trivial:
• Every octal digit becomes 3 binary digits
• Example: (17.5 ) 8
=(001 111 . 101) 2
Binary to Octal
• Just as simple, reverse to process
• Example: (11001010101.011101) 2
=(011 001 010 101 . 011 101) 2
=(3125.35) 8
• Note: Using the hex and octal equivalent
instead of binary numbers are more
convenient and less prone to errors.