0% found this document useful (0 votes)
85 views

Chap 2 2.1.1 Binary, Octal, Hexadecimal

The sum of A C 5 A 9 + E D 6 9 4 in hexadecimal is 13D3.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Chap 2 2.1.1 Binary, Octal, Hexadecimal

The sum of A C 5 A 9 + E D 6 9 4 in hexadecimal is 13D3.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 90

DFC 10223

CHAPTER 2 : ARITHMETIC AND LOGIC

DATA
REPRESENTATION
IN COMPUTER
MEMORY

Lesson Learning Outcome:


Convert decimal, binary, octal and hexadecimal numbers to different bases
and vice-versa.
INTRODUCTION
The binary system and decimal system is
most important in digital system.
Decimal - Universally used to represent
quantities outside a digital system.
Its means, there will be situations decimal
values must be converted to binary values
before entered to digital system.
Example : Calculator / Computer

03/21/24
2.1 Understand data representation
on CPU.
2.1.1 Define decimal, binary, octal and
hexadecimal number.

2.1.2 Perform arithmetic operation (addition


and subtraction) in different number
bases.

2.1.3 Convert decimal, binary, octal and


hexadecimal numbers to different bases
and vice-versa
03/21/24
Topic 2.1.2

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

How to calculate in decimal =2746.210


3 2 1 0 -1
2 7 4 6. 2

= (2 x 103) + (7 x 102) + (4 x 101) + (6 x 100) + (2 x 10-1)


= 2000 + 700 + 40 + 6 + . 0.2
= 2746.210
03/21/24
03/21/24
Addition & Subtraction for
decimal number
Calculate 5.84 + 8 + 12.79.

Subtraction 3.67 – 1.83 in decimal number

03/21/24
BINARY DIGIT
A Binary Digit can only be 0 or 1

Binary 0 1 10 11 100 101 110 111 1000 1001 1010


Decimal 0 1 2 3 4 5 6 7 8 9 10

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

 A collection of n bits has 2n possible states.

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

 Add 10001 and 11101.

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 =

ii) 1111012 + 101112 =

iii) 001112 + 101012 =

03/21/24
Exercises
1010100+11100= 1110000

10110100
10101001+1011=

100010010
10101+11111101=

1001010
101011+11111=

03/21/24
Subtract binary numbers

Subtraction Binary Formula


0 - 0 = 0

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

 Subtract 1011011 with10010 Subtract 11100 with 1111

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

Example 6 + 5 = 11 in decimal no > = 8 YES


68 + 58 = 138 If computation octal >= 8 carry forward 1 at front
1X
X= 11-8 = 3
So total 6+5 in octal no is 13

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

Ex. 2 : 4578 + 2458 = ?

 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"

= 53,248 + 256 + 192 + 14


= 53,710

03/21/24
The Point !
Example: 2E6.A3

This is 2×16×16 + 14×16 + 6 + . 10/16 + 3/(16×16)

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:

1. Add one column at a time A C 5 A 9


9+4 = 13 <16
2. Convert to decimal & add (9 + 4 = 13)
3. Follow less than 16 rule
E D 6 9 4 =D
Decimal 13 is hexadecimal D D

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

1.Add next column A C 5 A 9


2.Convert to decimal & add (1 + 5 + 6 = 12) 1 +5 + 6 =12 <16
E D 6 9 4
3.Follow less than 16 rule, convert to hex =C
Decimal 12 is hexadecimal C C 3 D

Carry Over: 1

1.Add next column A C 5 A 9


2.Convert to decimal & add (12 + 13 = 25) E D 6 9 4 12 + 13 = 25 > 16
3.Follow 16 or larger than 16 rule = 1 (25-16)
(25 – 16 = 9 carry a 1) 9 C 3 D
= 19

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

1.Add next column 0 A C 5 A 9 1


2.Convert and add (1 + 0 + 0 = 1)
0 B D 6 9 4
3.Follow less than 16 rule
1 6 9 C 3 D

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

20D316 + 12BC16 = 338F16

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

325516 – 318216 = D316

03/21/24
Exercises…DIY
21E316 - 31F16 =

D0C316 - BEE316 =

C75316 - A2816 =

03/21/24
Topic 1.2.3

Convert decimal, binary, octal


and hexadecimal numbers to
different bases and vice-versa

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^

Numbering System / Arithmetic numbers:


1.Decimal (N10)
2.Binary (N2)
3.Octal (N8)
4.Hexadecimal (N16)
03/21/24
How to do conversion using
formula
Involve formula x ^
Convert binary to decimal N2
Convert octal to decimal
3 bit
Convert hexadecimal to decimal 4 bit
÷2 X^
Involve bit comparator (3-4 bits)
Convert Binary to octal
Convert Octal to binary ÷8 ÷16
Convert Binary to Hex N8 N10 N16
X^ X^
Convert Octal to Hex
Convert Hex to Octal

Involve formula divider (÷)


Convert Decimal to Binary
Convert Decimal Octal
Convert Decimal to Hexadecimal

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

Convert binary 10112 to the corresponding decimal


number.
3 2 10

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

 Convert 5458 to the corresponding decimal number.

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.

Convert Hexadecimal into decimal number


 ABC16 =
 = (A x 162) + (B x 161) + (C x 160)
 = (10 x 162) + (11 x 161) + (12 x 160)
 = (10 x 256) + (11 x 16) + (12 x 1)
 = (2560 + 176 + 12 )
 = 274810
03/21/24
Hex to Decimal
(6E9.D8)16
= 6 × 162 + 14 × 161 + 9 × 160 + . 13 × 16(-1) + 8 × 16(-2)

= 6 x 256 + 14 x 16 + 9 x1 . 13 x 0.5 + 8 x 0.03125


= 1536 + 224 . + 0.84375
(1769.84375)10

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 ÷

Convert Decimal to Binary


Convert Decimal Octal
Convert Decimal to Hexadecimal
N2

÷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?

Convert 3010 to binary number?

Convert 63 10 to binary number?

Convert 12510 to binary number?


03/21/24
Decimal to octal
3 10 = (?)8
(152.512)

03/21/24
Decimal to octal
 convert 2980 into octal digit

convert 12345 into octal digit

03/21/24
exercises
Decimal – octal

1. decimal 65 – octal

2. decimal 123 - 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

2. 365 - 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)

1. Create 6 group (7 people/group)- 2 minutes


2. Get a topic, marker pen, paper
3. Discuss in group
4. Write the answer in paper given
5. Present your answer.

03/21/24
Example 3
3. Convert 11010112 to octal and hexadecimal.

4. Convert 43.678 to binary and hexadecimal.

5. Convert B8.1C16 to decimal and octal

6. Convert 234.1610 to binary and hexadecimal

7. Convert 74.528 to decimal


03/21/24
Conclusion
Students are to convert decimal, binary,
octal and hexadecimal numbers to
different bases and vice-versa.

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

 10101011 Binary – Octal

10111.01101 Binary – Octal

 10101011 Binary – Hex

10111.01101 Binary – Hex

03/21/24
Octal to Binary
(3 bits comparator)
Octal = 3 7 2

Binary = 011 111 010 = 011111110 binary

Octal – Binary (3 bits comparator)

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

Octal 274 – Binary

Octal 375.12 – Binary

Hex 274 – Binary

Hex 375.12 – Binary

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

Octal – binary - hexadecimal

03/21/24
exercises
Convert Octal – Hex

1. 472 octal – Hex

2. 645 – hex

3. 645.13 - hex


03/21/24
Hex to octal
 Step 1: Each digits convert to binary using 4 bits
comparator
 Step 2: Then separate the binary digits using 3bits
comparator and get the value into octal number.

03/21/24
Hexadecimal to Octal
Hexadecimal (4bits) – Binary (3bits) - Octal

03/21/24
exercises
Hex – octal

1. 6FE1 – octal

2. 3A7D – octal

3. 3A7D. 9B – octal

03/21/24
03/21/24
03/21/24
90

You might also like