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

Representation of Numbers

Computers use binary to represent data internally. There are different number systems like binary, decimal, octal, and hexadecimal to represent numbers. Binary uses only two digits, 0 and 1. It is the base system for computers. Decimal uses 0-9 and is base 10. Hexadecimal uses 0-9 and A-F, representing 4 binary bits, and is base 16. Numbers can be converted between these systems using division and multiplication by the base.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Representation of Numbers

Computers use binary to represent data internally. There are different number systems like binary, decimal, octal, and hexadecimal to represent numbers. Binary uses only two digits, 0 and 1. It is the base system for computers. Decimal uses 0-9 and is base 10. Hexadecimal uses 0-9 and A-F, representing 4 binary bits, and is base 16. Numbers can be converted between these systems using division and multiplication by the base.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Machine Representation of

Numbers and Characters


What is Data Representation in Computer?
• A computer uses a fixed number of bits to represent a piece
of data which could be a number, a character, image, sound,
video, etc.

• Data representation is the method used internally to


represent data in a computer.

• Computers manipulate representations of things!

Page 2
Number Systems
• Number systems are the technique to represent numbers in the
computer system architecture, every value that you are saving or
getting into/from computer memory has a defined number system

• A number is a mathematical object used to count, label, and


measure.

• A number system is a systematic way to represent numbers.

21 November 2022 Page 3


Computer architecture supports the following
number systems:

1) Binary Number System

2) Octal Number System

3) Decimal Number System

4) Hexadecimal Number System

21 November 2022 Page 4


Binary Number System
• A Binary number system has only two digits that are 0 and 1.
Every number (value) represents 0 and 1 in this number
system. The base of the binary number system is 2 because it
has only two digits.
• A binary digit is called a bit.

BASE 2

• 1011010 = 1x 2 6 + 0x25 + 1x24 + 1x23 + 0x22 + 1x2 + 0x1 = 64 +


16 + 8 + 2 = 90

21 November 2022 Page 5


Binary Number Table
DECIMAL BINARY DECIMAL BINARY
1 001 11 1011
2 010 12 1100
3 011 13 1101
4 100 14 1110
5 101 15 1111
6 110 16 10000
7 111 17 10001
8 1000 18 10010
9 1001 19 10011
10 1010 20 10100

21 November 2022 Page 6


Binary Addition
• The binary addition operation works similarly to the base 10
decimal system, except that it is a base 2 system.

• The four rules of binary addition are:


0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10

21 November 2022 Page 7


Example
1. 101
(+) 101

1 1
101 101 101
(+) 101 (+) 101 (+) 101
0 10 1010

21 November 2022 Page 8


Example
2. 1 0 0 0 1 10001
(+) 1 1 1 0 1 (+) 1 1 1 0 1
101110

3. 1 0 1 0 1 10101
(+) 1 1 0 1 1 (+) 1 1 0 1 1
110000

21 November 2022 Page 9


Binary Subtraction
• Subtraction of binary numbers is an arithmetic operation similar to
the subtraction of decimal numbers or base 10 numbers.

• The four rules of binary Subtraction are:

0 - 0 = 0
0 - 1 = 1 (Borrow 1 from the next high order digit)
1 - 0 = 1
1 - 1 = 10

21 November 2022 Page 10


Example
1. 11010
(+) 10110

1
11010 11010 11010
(+) 10110 (+) 10110 (+) 10110
0 00 00100

21 November 2022 Page 11


Example
2. 1 0 1 0 1010
(-) 1 0 1 (-) 1 0 1
0101

3. 0 0 1 1 0 1 0 0011010
(-) 0 0 1 1 0 0 (-) 0 0 1 1 0 0
0001110

21 November 2022 Page 12


Binary to Decimal

• Converting a number in a binary number system (base-2) to a


number in a decimal number system is known as binary to
decimal conversion (base-10)

21 November 2022 Page 13


Example
1. (10011)2

(10011)2 = (1 × 24) + (0 × 23) + (0 × 22) + (1 × 21) + (1 × 20)


= 16 + 0 + 0 + 2 + 1 = (19)
(10011)2 = 1910

21 November 2022 Page 14


Example
2. (1101)2

(1101)2 = (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20)


= 8 + 4 + 0 + 1 = (13)
(1101)2 = 1310

21 November 2022 Page 15


Activity: Binary Number system
1. Convert 111102 into a decimal number system
2. Convert the binary number 11101102 into a decimal number system
3. Convert the binary number 01010012 into a decimal system.
4. Subtract the given binary number 0011010 – 001100.
5. Subtract the given binary number 0100010 – 0001010.
6. Subtract the given binary number 10110 - 1101.
7. Add the given binary number 1101 + 1001.
8. Add the given binary number 110011 + 101100.
9. Add the given binary number 110 + 1010 + 1001.

21 November 2022 Page 16


Decimal Number
• Decimal number system has ten symbols: 0, 1, 2, 3, 4, 5, 6, 7,
8, and 9, called digits. Every number (value) represents with
0,1,2,3,4,5,6, 7,8 and 9 in this number system. The base of
decimal number system is 10, because it has only 10 digits.

21 November 2022 Page 17


Example
1. Convert 17410 to binary

174 ÷ 2 87 0 (LSB)
87 ÷ 2 43 1

Bottom to Top
43 ÷ 2 21 1
Answer:
21 ÷ 2 10 1
10 ÷ 2 5 0 101011102
5÷ 2 2 1
2÷ 2 1 0
1÷ 2 0 1 (MSB)

21 November 2022 Page 18


Example
2. Convert 156 to binary

156 ÷ 2 78 0 (LSB)
78 ÷ 2 39 0

Bottom to Top
39 ÷ 2 19 1
Answer:
19 ÷ 2 9 1
9 ÷ 2 4 1 100111002
4 ÷ 2 2 0
2 ÷ 2 1 0
1 ÷ 2 0 1 (MSB)

21 November 2022 Page 19


Activity: Decimal Number system
1. Convert 5710 to binary
2. In a decimal to binary conversion, the base of the number
changes from 2 to 10. True or False?
3. Convert 29410 to binary
4. Subtract the given binary number 0100010 – 0001010.
5. Subtract the given binary number 10110 - 1101.
6. Add the given binary number 1101 + 1001.
7. Add the given binary number 110011 + 101100.
8. Add the given binary number 110 + 1010 + 1001.

21 November 2022 Page 20


Hexadecimal Number System
• A hexadecimal number system is one of the types of number
systems along with binary, octal, and decimal.

• The base number of a hexadecimal number system is 16 where


it includes both numbers from 0 -9 and digits from A - F.
Hexadecimal is considered as one of the most convenient ways
to showcase a binary number in computers and is done by
using a conversion table.
21 November 2022 Page 21
Hexadecimal Number System
• The word hexadecimal can be divided into 'Hexa' and 'deci', where
'Hexa' means 6 and 'deci' means 10.
• A hexadecimal number system is also known as a positional number
system as each digit has a weight of power 16. Each digit is 16
times more significant than the previous digit.
• In hex, four digits of a binary number can be represented by a
single hex digit. The binary digits are expressed in 4.

21 November 2022 Page 22


HEXADECIMAL DECIMAL BINARY
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100

Hexadecimal 5 5 0101

Number System
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
21 November 2022 Page 23
Hexadecimal Number System
Method 1: Convert Hexadecimal to Binary with Conversion Table
Example: Convert hexadecimal (67F)16 to binary.

6 = (6)10 , 7 = (7)10 , F = (15) 10


Once the decimal of each digit is obtained, looking at the
conversion table convert each decimal number to binary.
(6) 10 = (0110)2
TOP TO BOTTOM

Answer:
(7) 10 = (0111)2
(F) 10 = (1111)2 (67F)16 = 0110011111112

21 November 2022 Page 24


Hexadecimal Number System
Method 2: Convert Hexadecimal to Binary without Conversion
Table.
This method requires both multiplication and division of
numbers using the respective base numbers.

Example: Convert hexadecimal (76)16 to binary.

21 November 2022 Page 25


Hexadecimal Number System
Method 2 : MULTIPLICATION (RULE FROM PAGE 38!)
Example: Convert hexadecimal (76)16 to binary.
(76) 16 = 7 × 161 + 6 × 160
(76) 16 = 7 × 16 + 6 × 1
(76) 16 = 112 + 6
(76) 16 = 118

Therefore, (76)16 = (118)10

21 November 2022 Page 26


Hexadecimal Number System
Method 2 : DIVISION (RULE FROM PAGE 38!)
Example: Convert hexadecimal (76)16 to binary.
118 ÷ 2 = 59 0

BOTTOM TO TOP
59 ÷ 2 = 29 1

29 ÷ 2 = 14 1
Answer:
14 ÷ 2 = 7 0

7 ÷ 2 = 3 1 (76F)16 = 11101102
3 ÷ 2 = 1 1

1 ÷ 2 = 1

21 November 2022 Page 27


Hexadecimal Number System
Example: Converting binary 110011110112 to hexadecimal.

We add zero because hex is 4 bit


Answer:
0110 0111 1011
110011110112 = 67B16
6 7 B

LEFT TO RIGTH

21 November 2022 Page 28


Activity: Hexadecimal Number system
1. Convert 11011000112 to hexadecimal
2. What is decimal equivalent is (78DE)2 ?
3. What is the hexadecimal equivalent of (50)8
4. Convert hexadecimal 51216 to binary using method 1 and 2

21 November 2022 Page 29


Octal
• Octal Number System is a type of number system that has a
base of eight and uses digits from 0 to 7.

• The word octal is used to represent the numbers that have


eight as the base.

21 November 2022 Page 30


Octal Number System
Example: Convert octal number (121)8 to its decimal form.

(121)8 = 1 x 82 + 2 x 81 + 1 x 80
= 1 x 64 + 2 x 8 + 1 x 1
= 64 + 16 + 1
Answer:
(121)8 = 8110

21 November 2022 Page 31


Octal Number System
Example: Convert decimal number (100)10 to its octal number.
remainder
100 ÷ 8 = 12 4

12.5
To get exact remainder, we need to multiply 0.5x 8

12 ÷ 8 = 1 1

1.5
To get exact remainder, we need to multiply 0.5x 8

21 November 2022 Page 32


Octal Number System
Example: Convert decimal number (100)10 to its octal number.
remainder
1 ÷ 8 = 0 1

0.1
To get exact remainder, we need to multiply 0.1x 8

100 ÷ 8 = 12 4 BOTTOM TO TOP Answer:


59 ÷ 8 = 1 4

29 ÷ 8 = 0 1 (100)10 = 1448
21 November 2022 Page 33
Octal Number System
Example: Convert decimal number (321)10 to its octal number.

BOTTOM TO TOP
321 ÷ 8 = 40 1
Answer:
40 ÷ 8 = 5 0

5 ÷ 8 = 0 5 (100)10 = 5018

21 November 2022 Page 34


Octal Number System
Example: Convert binary number (101101)2 to its octal number.
Binary to Octal Conversion Table
Binary Octal Divide the binary digits into groups of three
000 0 3-bits (starting from right) for integer part.

001 1 101 101


010 2 5 5
011 3
100 4
Answer:
101 5
110 6 (101101)10 = 558
111 7

21 November 2022 Page 35


Octal Number System
Example: Convert octal number (2322)8 to its decimal form.

(2322)8 = 2 x 83 + 3 x 82 + 2 x 81 + 2 x 80
= 2 x 512 + 3 x 64 + 2 x 8 + 2 x 1
= 1024 + 192 + 16 + 2
Answer:
(2322)8 = 123410

21 November 2022 Page 36


Octal Number System
Example: Convert binary number (1010111100)2 to octal.

= 10101111002
= 001 010 111 1002
= 1 2 7 4

Answer:
(1010111100)2 = 12748

21 November 2022 Page 37


Octal Number System
Example: Convert decimal number (92)10 to its octal number.

92 ÷ 8 = 11 4
Answer:
11 ÷ 8 = 1 3

1 ÷ 8 = 0 1 (192)10 = 1348

21 November 2022 Page 38


Activity: Octal Number system
1. Convert octal number (2322)8 to its decimal form.
2. Convert binary number (1010111100)2 to octal.
3. Convert decimal number 9210 to Octal form

21 November 2022 Page 39

You might also like