Chap 2 2.1.1 Binary, Octal, Hexadecimal
Chap 2 2.1.1 Binary, Octal, Hexadecimal
DATA
REPRESENTATION
IN COMPUTER
MEMORY
03/21/24
2.1 Understand data representation
on CPU.
2.1.1 Define decimal, binary, octal and
hexadecimal number.
03/21/24
Numbering System / Arithmetic numbers:
Binary (N2) - (0, )
Octal (N8) - (0,1,2,3,4,5,6,7)
Decimal (N10) – (0,1,2,3,4,5,6,7,8,9)
Hexadecimal (N16)
- (0 1 2 3 4 5 6 7 8 9, A, B, C, D, E, F)
03/21/24
DECIMAL NUMBERING SYSTEM
Decimal system is composed of 10 numerals or
symbols.
These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Using these symbols as digits of a number, it
can express any quantity.
Base number = 10
Basic number = 0,1,2,3,4,5,6,7,8,9
03/21/24
Decimal calculation
Decimal (N10)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
03/21/24
BINARY DIGIT
A Binary Digit can only be 0 or 1
03/21/24
BITS
Basic unit of information is the binary digit, or bit.
Values with more than two states require multiple bits.
• A collection of two bits has four possible states:
00, 01, 10, 11
• A collection of three bits has eight possible states:
000, 001, 010, 011, 100, 101, 110, 111
03/21/24
Bits Tables
3 bit table 4 bit table
03/21/24
Add binary numbers
Addition Binary Formula
0 + 0 = 0 0= 00
1= 01
0 + 1 = 1 2= 10
3= 11
1 + 0 = 1
1 + 1 = 0 carry 1 forward 1 1
1 1 + 1 = 1 carry 1 forward 1 1 0 1 12
Ex. 1 : 110112 + 100012 = + 1 0 0 0 12
1011002
1 0 1 1 0 02
1 1 1
1 0 1 1 12
Ex. 2 : 101112 + 1112 =
11110
+ 1 1 12
1 1 1 1 02
03/21/24
More example binary addition
Add 10010 and 1001. Add 1101 and 1111
03/21/24
Fractions: Fixed-Point
How can we represent fractions?
Use a “binary point” to separate positive
from negative powers of two -- just like “decimal
point.”
2’s comp addition and subtraction still work.
if binary points are aligned 2-1 = 0.5
2-2 = 0.25
2-3 = 0.125
00101000.101 (40.625)
+ 11111110.110 (-1.25)
00100111.011 (39.375)
No new operations -- same as integer arithmetic.
03/21/24
Exercises….Do it now!
i) 11102 + 01112 =
03/21/24
Exercises
1010100+11100= 1110000
10110100
10101001+1011=
100010010
10101+11111101=
1001010
101011+11111=
03/21/24
Subtract binary numbers
1 - 1 = 0
1 - 0 = 1
1
0 - 1 = 1 borrow 1 from front (2-1=1)
Ex.1 : 1001 2 - 10 2 = 1 0 0 12
111 2 - 1 02
0 1 1 12
1 2 2
1 0 1 0 1 12
- 1 1 1 12
Ex. 2 : 101011 2 - 1111 2
=?
03/21/24
1 1 1 0 02
03/21/24
More example binary subtraction
Subtract 1000101 with 101100 Subtract 100001 with 11111
03/21/24
Exercises
10101001-1111 = 10011010
10111-1011= 1100
1010000-10111= 111001
1111100-1110= 1101110
03/21/24
Octal
Octal (N8)
0, 1, 2, 3, 4, 5, 6, 7
An older computer base system is "octal", or
base eight. The digits in octal math are 0, 1, 2, 3,
4, 5, 6, and 7.
The octal number system has a base of eight,
meaning that it has eight possible digits:
0,1,2,3,4,5,6 and 7.
03/21/24
Octal Addition
The octal number system consists of 8
digits ranging from 0 to 7.
Octal is another number system with less
symbols to use than our conventional
number system. They are 0, 1, 2, 3, 4, 5,
6, and 7. When we count up one from the
7, we need a new placement to represent
what we call 8 since an 8 doesn't exist in
Octal. So, after 7 is 10.
03/21/24
Addition for octal No
03/21/24
Exercises
(162)8 + (537)8
162
+537
721
(25.27) 8 + (13.2) 8
25.27
+13.2
40.47
03/21/24
Exercises
Ex. 1 : 1238 + 3218 = 4448
6578 + 5578 = ?
172378 + 6438 = ?
03/21/24
Subtraction in octal numbers
03/21/24
Subtraction in octal numbers
5248 - 1678 = 3358
7-4 = 3
6-2 =4
1678 - 248 = ?
=143
5238 - 748 = ?
03/21/24
Exercises
1268 - 678 =
12028 - 1378 =
25028 - 2418 =
15038 - 12458 =
03/21/24
Hexadecimals
A Hexadecimal Number is based on the
number 16
There are 16 Hexadecimal digits. They are
the same as the decimal digits up to 9, but
then there are the letters A, B, C, D, E and
F in place of the decimal numbers 10 to
15:
Hexadecimal: 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
03/21/24
Example: What is the decimal value of
the hexadecimal number "D1CE"
03/21/24
The Point !
Example: 2E6.A3
03/21/24
03/21/24
Addition in Hexadecimal
The problem:
A C 5 A 9
E D 6 9 4
You are to add these numbers:
Carry Over:
Carry Over: 1
A C 5 A 9
1.Add next column
2.Convert to decimal & add (10 + 9 = 19) 10+9 = 19 >16
E D 6 9 4
3.Follow 16 or larger than 16 rule = 1 (19-16)
(19 – 16 = 3 carry a 1) 3 D = 13
03/21/24
Carry Over: 1
Carry Over: 1
Carry Over: 1
1.Add next column A C 5 A 9 1 + 10 + 11 = 22 >16
2.Convert and add (1 + 10 + 11 = 22) B D 6 9 4 = 1 (22-16)
3.Follow 16 or larger than 16 rule 6 9 C 3 D = 16
(22 – 16 = 6 carry a 1)
03/21/24
Carry Over: 1
03/21/24
Addition in Hex
Add 16F16 + 4A216.
1 1 ← Carried over digits
1 6 F
+ 4 A 2
----------------
6 1 1
-----------------
03/21/24
Add hexadecimal
03/21/24
Exercise
3316 + 4716 = 7A16
A1D316 + BD2C16 =
03/21/24
Exercises…DIY
20E316 + 131F16 =
50C316 + 1ED316 =
875316 + 1A5316 =
12716 + 1A616 =
03/21/24
Hexadecimal Subtraction
03/21/24
Subtract Hexadecimal numbers
4416 – 1716 = 2D16 = 4 – 7 cannot borrow 16 from left
= 16 +4 = 20 -7 =13 < 16
= 13 = D
= 3 -1 = 2
03/21/24
Exercises…DIY
21E316 - 31F16 =
D0C316 - BEE316 =
C75316 - A2816 =
03/21/24
Topic 1.2.3
03/21/24
2.1.3 Conversion Numbers
Binary (N2) - (0 1)
Octal (N8) - (0,1,2,3,4,5,6,7)
Decimal (N10) – (0,1,2,3,4,5,6,7,8,9)
Hexadecimal (N16)
- (0 1 2 3 4 5 6 7 8 9, A, B, C, D, E, F)
03/21/24
Conversion Numbers
N2
3 bit 4 bit
÷2 X 2^
÷8 ÷16
N8 N10 N16
X 8^ X 16^
03/21/24
Involve formula X^
Convert binary to decimal
Convert octal to decimal
Convert hexadecimal to decimal
N2
X^
N8 N10 N16
X^ X^
03/21/24
How to convert binary to decimal value
Binary (N2)
0 and 1
10112
= (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20)
= 8+0+2+1
= 1110
03/21/24
Convert binary to decimal value
Try for yourself….!
convert the binary value 100101.01
to decimal number N2
3 bit 4 bit
÷ X^
÷ ÷
N8 N10 N16
X^ X^
03/21/24
Binary to Decimal
binary number 011010 means in decimal number
= 0 × 2 5 + 1 × 24 + 1 × 23 + 0 × 22 + 1 × 21 + 0 × 20
03/21/24
Binary to decimal
(1101.01)2
= 1 × 23 + 1×22 + 0 × 21 + 1 × 20 + . 0 × 2(-1) + 1 × 2(-2)
= 1 × 8 + 1×4 + 0 × 2 + 1 × 1 +. 0×5 + 1 × 0.25
= 8 + 4 + 0 + 1 +.0 + 0.25
= 13.2510
03/21/24
Octal to Decimal
Answer.
= 545
= 5×82 + 4×81 + 5×80
= 5×64 + 4×8 + 5×1
= 320 + 32 + 5
= 357
03/21/24
Octal to Decimal
Example
Convert 1077.1058 to the corresponding
decimal number.
1077.1058
= (1 x 83) + (0 x 82) + (7 x 81) + (7 x 80) +
(1 x 8-1) + (0 x 8-2 ) + ( 5 x 8-3 )
= 512 + 0 + 56 + 7 . + 0.125 + 0 +
0.00977
= 575.134710
03/21/24
Octal to Decimal
(431.2)8
= 4 × 82 + 3 × 81 + 1 × 80 + 2 × 8(-1)
= 4 x 64 + 3 x 8 + 1 x 1 +. 2 x 0.125
= 256 + 24 + 1 + . 0.25
= 281 + 0.25
= 281.2510
03/21/24
Hexadecimal to Decimal
Hexadecimal (N16)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
03/21/24
Exercises 1
1. Convert all the numbers:
a.372.458 - N10
b.3B916 – N10
c.101101.102 – N10
03/21/24
Hex to Decimal
03/21/24
Involve formula Divider ÷
÷2
÷8 ÷ 16
N8 N10 N16
03/21/24
03/21/24
Decimal to Binary
Convert 32 to binary digit convert 156 to binary digit
156 = 10011100
03/21/24
Decimal to binary (pointer)
(31.6875)10 = (?)2
03/21/24
Exercises
Decimal to Binary
Exercises
Convert 5810 to binary number?
03/21/24
Decimal to octal
convert 2980 into octal digit
03/21/24
exercises
Decimal – octal
03/21/24
Decimal to hex
Convert 15605605 decimal to hex convert 415 decimal to hex
03/21/24
Decimal to Hex
(2607.565)10 = (?)16
03/21/24
exercises
Decimal – Hex
1. 89 – hex
03/21/24
Example 2
2. Convert 6410 to:
a.Binary (N2)
b.Octal (N8)
c.Hexadecimal (N16)
03/21/24
Activity 1 : Discussion (20 minutes)
03/21/24
Example 3
3. Convert 11010112 to octal and hexadecimal.
03/21/24
Involve bit comparator (3-4 bits)
Convert Binary to octal
Convert Octal to binary
Convert Binary to Hex
Convert Octal to Hex
N2
Convert Hex to Octal
3 bit 4 bit
N8 N10 N16
03/21/24
Conversion Value
Binary Decimal Octal Hexadecimal
0000 0 00 0
0001 1 01 1
0010 2 02 2
0011 3 03 3
0100 4 04 4
0101 5 05 5
0110 6 06 6
0111 7 07 7
1000 8 10 8
1001 9 11 9
1010 10 12 A
1011 11 13 B
1100 12 14 C
1101 13 15 D
1110 14 16 E
1111 15 17 F
03/21/24
Binary to octal
Decimal Binary Octal
Convert 10010101 to octal number 0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
N2 7 111 7
3 bit 4 bit
÷ X^
÷ ÷
N8 N10 N16
X^ X^
03/21/24
Binary to Hex
N2
3 bit 4 bit
÷ X^
÷ ÷
N8 N10 N16
X^ X^
03/21/24
Excercises
03/21/24
Octal to Binary
(3 bits comparator)
Octal = 3 7 2
03/21/24
Hex to Binary
Hex - Binary (4 bits comparator)
Divide each digits can convert the digits
into binary value
03/21/24
exercises
03/21/24
Octal to hex
Step 1: Each digits convert to binary using 3 bits
comparator
Step 2: Then separate the binary digits using 4 bits
comparator and get the value into hex number.
03/21/24
Octal to Hexadecimal
Step 1: 3 bits Step 2: 4 bits
03/21/24
exercises
Convert Octal – Hex
03/21/24
Hexadecimal to Octal
Hexadecimal (4bits) – Binary (3bits) - Octal
03/21/24
exercises
Hex – octal
03/21/24
03/21/24
03/21/24
90