Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

Chapter 3

Data Representation
and
The Number System
What is the meaning of
representation of data?
Data Representation refers to the
methods used internally to represent
or symbolize information stored in a
computer.

Computers store lots of different


types of information: numbers,
text, Pictures and etc.
What is a numbering system?
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.
Simply put, a number system is a way to
represent numbers.
We are used to using the base-10 number system,
which is also called decimal. Other common number
systems include base-16 (hexadecimal), base-8 (octal),
and base-2 (binary).
What is the use of number system in
computers?

Its simple really - a computer is made millions of circuits. A


circuit can only be on or off to make electricity flow or not
flow through it. The 0 and 1 of binary is simply an on or off
switch for a circuit.
Since the computer works with the binary number
system and since it is relatively easy to
convert hexadecimal (base 16) and octal numbers (base
8) into binary,
Computer scientists need to be familiar with
the octal and hexadecimal number systems.
Decimal Numbering System
In the Decimal system a digit can take
one out of ten different values (0..9)

A number in the decimal system is


expressed by the following expression:
by base-10

Example (58)10, (120)10, (321)10 etc…


Binary Numbering System
• Binary number system mean “Base 2
system”
• The binary number system is used to model the
series of electrical signals computers use to
represent information.
• 0 represents the no voltage or an off state
• 1 represents the presence of voltage or an
on state
Binary Numbering System cont.…
Powers of 2:
•A binary digit is called the BIT (BInary digiT) 0
2 =1
•A group of eight bits is called the BYTE. 1
2 =2
2
2 =4
3
2 =8
•A binary system with N bits can represent the 4
2 = 16
N-1 5
2 = 32
numbers from 0 to 2 . 6
2 = 64
7
2 = 128
N 8
2 = 256
•In a binary system with N digits there are 2 9
2 = 512
different combinations. 10
2 =1024=1KB
16
2 = 65536

•A binary number is multiplied by two, if we


append a zero.
Binary Numbering System cont.…
• Digital systems and computers use the
Binary system because it has only two
states (0 and 1)

• A number in the Binary system is


expressed by the following expression:
Binary Numbering Scale
Base 2 Number Base 10 Equivalent Power Positional Value

00000000 0 20 1
00000001 1 21 2
0010 2 22 4
0011 3 23 8
0100 4 24 16
0101 5 25 32
0110 6 26 64
0111 7 27 128
1000 8 28 256
00001001 9 29 512
00001010 10 210 1024
Conversion Among Bases
• The possibilities:

Decimal Octal

Binary Hexadecimal
Decimal to Decimal

Decimal Octal

Binary Hexadecimal

Next slide…
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

Base
Binary to Decimal

Decimal Octal

Binary Hexadecimal
Binary to Decimal
• Technique
–Multiply each bit by Nx2n-1, where N is
the “weight” of the bit
–n weight is the position of the bit,
starting from 0 on the right
–Add the results
Examples
1. (1011)2 = (1X23 )+(0X22)+(1X21) +(1X20)
= 8+0+2+1
= (11)10

2. (10110)2 = (1X24 )+(0X23)+(1X22) +(1X21) +(0X20)


= 16+0+4+2+0
= (22)10

3. (101100)2 =(1X25
)+(0X24)+(1X23)+(1X22)+(0X21)+(0X20)
=32+0+8+4+0+0
= (44)10
Binary to Decimal Conversion cont…
• The easiest method for converting a binary number to
its decimal equivalent is to use the Multiplication
Algorithm

• Multiply the binary digits by increasing powers of two,


starting from the right

• Then, to find the decimal number equivalent, sum


those products.
D=nx2n-1
Multiplication Algorithm
Convert (10101101)2 to its decimal equivalent:

Binary 1 0 1 0 1 1 0 1
x x x x x x x x
Positional Values 27 26 25 24 23 22 21 20

Products 128 + 0 + 32 + 0 + 8 + 4 + 0 +1

(173)10
Octal to Decimal

Decimal Octal

Binary Hexadecimal
Octal to Decimal
• Technique
– Multiply each bit by Nx8n-1, where N is the “weight” of the bit
– The n weight is the position of the bit, starting from 0 on the
right
– Add the results
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by Nx16n-1, where n is the “weight” of the bit
– The weight is the position of the bit, starting from 0 on the right
– Add the results
Hexadecimal to Decimal Conversion
Convert 3B4F to its decimal equivalent:

Hex Digits
3 B 4 F
x x x x
Positional Values
163 162 161 160
Products 12288 +2816 + 64 +15

15,18310
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary

Decimal Octal

Binary Hexadecimal
Decimal to Binary Conversion
• The easiest way to convert a
decimal number to its binary
equivalent is to use the Division
Algorithm
• This method repeatedly divides a
decimal number by 2 and records
the remainder
–The remainder digits (a sequence of
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1
– Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012
Division Algorithm
Convert 67 to its binary equivalent:
6710 = x2
Step 1: 67 / 2 = 33 R 1 Divide 67 by 2. Record quotient in next row

Step 2: 33 / 2 = 16 R 1 Again divide by 2; record quotient in next


row

Step 3: 16 / 2 = 8 R 0 Repeat again

Step 4: 8 / 2 = 4 R 0 Repeat again

Step 5: 4 / 2 = 2 R 0 Repeat again

Step 6: 2 / 2 = 1 R 0 Repeat again

Step 7: 1 / 2 = 0 R 1 STOP when quotient equals


0

1 0 0 0 0 1 12
Octal to Binary

Decimal Octal

Binary Hexadecimal
Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent binary
representation
Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit equivalent binary
representation
Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Decimal to Octal

Decimal Octal

Binary Hexadecimal
Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder
Example
123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228
Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Decimal to Hexadecimal Conversion
Convert 83010 to its hexadecimal equivalent:

830 / 16 = 51 R14
51 / 16 = 3 R3 = E in Hex

3 / 16 = 0 R3

33E16
Example
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216
Binary to Octal

Decimal Octal

Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278
Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Binary to Hexadecimal Conversion
• The easiest method for converting binary to hexadecimal is to use
a substitution code
• Each hex number converts to 4 binary digits
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Octal to Hexadecimal
• Technique
– Use binary as an intermediary
Example
10768 = ?16

1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
55 A B C
D 11100101 E F
G H 7013 I
J K L dAF

Don’t use a calculator!

Skip answer Answer


Binary Addition (2 of 2)
• Two n-bit values
– Add individual bits
– Propagate carries
– E.g.,
1 1
10101 21
+ 11001 + 25
101110 46
Multiplication (1 of 3)
• Decimal (just for fun)

35
x 105
175
000
35
3675

pp. 39
Multiplication (2 of 3)
• Binary, two 1-bit values

A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)
• Binary, two n-bit values
– As with decimal values
– E.g., 1110
x 1011
1110
1110
0000
1110
10011010
Fractions
• Decimal to decimal (just for fun)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14
Fractions
• Binary to decimal
10.1011 => 1 x 2-4 = 0.0625
1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions
.14579
• Decimal to binary x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Don’t use a calculator!

Skip answer Answer

You might also like