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

Computer Number System

The document discusses different number systems used in computing including binary, octal, decimal, and hexadecimal. It provides examples of how to represent numbers in each system and how to convert between the different bases. The key methods covered are dividing numbers by the new base to convert to binary, grouping binary digits into octal or hexadecimal to convert in the other direction, and using place values and weights to determine the contribution of each digit when converting between decimal, binary, octal, and hexadecimal.

Uploaded by

HA? HART
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Computer Number System

The document discusses different number systems used in computing including binary, octal, decimal, and hexadecimal. It provides examples of how to represent numbers in each system and how to convert between the different bases. The key methods covered are dividing numbers by the new base to convert to binary, grouping binary digits into octal or hexadecimal to convert in the other direction, and using place values and weights to determine the contribution of each digit when converting between decimal, binary, octal, and hexadecimal.

Uploaded by

HA? HART
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Computer

number system
Learning objectives
At the end of the lesson, the students should be able to:
1. Explain and identify the different number systems
2. Convert decimal to binary, octal, and hexadecimal
3. Convert binary to decimal, octal and hexadecimal
4. Convert octal to decimal, binary, and hexadecimal
5. Convert hexadecimal to decimal, binary, and octal

Computer Number System 2


Common number system

Used by Used in
System Base Symbols
humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
0, 1, … 9,
Hexadecimal 16 No No
A, B, … F
Computer Number System 3
Binary number system

•Also called the base-2 system


•Uses only two digits
§0 and 1 which are called bits
•All numbers and alphabetic characters that a
computer reads as input data is translated
into combination of two bits

Computer Number System 4


Octal number system
• Uses exactly eight symbols:
§ 0,1,2,3,4,5,6, and 7
• Base 8 is convenient shorthand for base 2 numbers
because 8 is a power of 2: 23=8
• One octal digit is equivalent of exactly three binary
digits
• Use of octal (or hexadecimal) as a shorthand for
binary is common printed output of main storage,
and in some cases, in programming
Computer Number System 5
hexadecimal number system

• Base 16 needs the ten symbols 0 through 9 and


six more.
• The six additional symbols used in hexadecimal
are the letters A through F.
• Uses exactly 16 symbols
§ 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F

Computer Number System 6


Conversion between
number bases
• It is sometimes convenient to use a number in a
base different from the base currently being used
• Many programmers can convert a number from
one base to another, among bases 10, 2, 8, and
16.

Computer Number System 7


Conversion between
number bases
• The possibilities:

Decimal Octal

Binary Hexadecimal

Computer Number System 8


Quantities/counting (1 of 3)
Decimal Binary Octal Hexa-decimal

0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Computer Number System 9
Quantities/counting (2 of 3)
Decimal Binary Octal Hexa-decimal

8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Computer Number System 10
Quantities/counting (3 of 3)
Decimal Binary Octal Hexa-decimal

16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17
Computer Number System 11
Summary of the
conversion method
To Base
From Base 2 8 16 10
Group binary digits by Group binary digits by Expand number and
2 3, convert 4, convert convert base 2 digits
to base 10
Convert each octal Convert to base 2, Expand number and
8 digit to 3 binary digits then to base 16 convert base 8 digits
to base 10
Convert each Convert to base 2, Expand number and
16 hexadecimal digit to 4 then to base 8 convert base 16 digits
binary digits to base 10
Divide number Divide number Divide number
repeatedly by 2; use repeatedly by 8; use repeatedly by 16; use
10
remainders as an remainders as an remainders as an
answer answer answer
Computer Number System 12
Positional notation

• Means that the value of a digit in number


depends not only on its own intrinsic value but
also on its location in the number

Digit 4th 3rd 2nd 1st (rightmost)


Position Thousand Hundred Ten Unit

Computer Number System 13


Quick example

2510 = 110012 = 318 = 1916

Base

Computer Number System 14


Decimal to Decimal
(just for fun)

Decimal Octal

Binary Hexadecimal

Computer Number System 15


Decimal to Decimal
(just for fun)
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125
Base

Computer Number System 16


Converting
base 2, 8, and 16 to base 10

•Binary to Decimal
•Octal to Decimal
•Hexadecimal to Decimal

Computer Number System 17


Binary to decimal

Decimal Octal

Binary Hexadecimal

Computer Number System 18


Binary to decimal

•Multiply each bit by 2n, 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

Computer Number System 19


Binary to decimal

1010112 => 1 x 20 = 1
1 x 21 = 2
Bit “0” 0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Computer Number System 20
Octal to decimal

Decimal Octal

Binary Hexadecimal

Computer Number System 21


Octal to decimal

•Multiply each bit by 8n, 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

Computer Number System 22


Octal to decimal

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

Computer Number System 23


Hexadecimal to decimal

Decimal Octal

Binary Hexadecimal

Computer Number System 24


Hexadecimal to decimal

•Multiply each bit by 16n, 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

Computer Number System 25


Hexadecimal to decimal

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


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

Computer Number System 26


Converting
base 10, 8, and 16 to base 2

•Decimal to Binary
•Octal to Binary
•Hexadecimal to Binary

Computer Number System 27


Decimal to binary

Decimal Octal

Binary Hexadecimal

Computer Number System 28


Decimal to binary

• Divide by two, keep track of the remainder


• First remainder is bit 0 (LSB, least-significant bit)
• Second remainder is bit 1
• Etc.

Computer Number System 29


Decimal to binary
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
Computer Number System 30
octal to binary

Decimal Octal

Binary Hexadecimal

Computer Number System 31


octal to binary

•Convert each octal digit to a 3-bit


equivalent binary representation

Computer Number System 32


octal to binary

7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

Computer Number System 33


Hexadecimal to binary

Decimal Octal

Binary Hexadecimal

Computer Number System 34


Hexadecimal to binary

•Convert each hexadecimal digit to a 4-bit


equivalent binary representation

Computer Number System 35


Hexadecimal to binary

10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

Computer Number System 36


Converting
base 10 to base 8, 16

•Decimal to Octal
•Decimal to Binary

Computer Number System 37


Decimal to octal

Decimal Octal

Binary Hexadecimal

Computer Number System 38


Decimal to octal

• Divide by 8
• Keep track of the remainder

Computer Number System 39


Decimal to octal
123410 = ?8

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

123410 = 23228

Computer Number System 40


Decimal to hexadecimal

Decimal Octal

Binary Hexadecimal

Computer Number System 41


Decimal to hexadecimal

• Divide by 16
• Keep track of the remainder

Computer Number System 42


Decimal to hexadecimal

123410 = ?16

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

123410 = 4D216
Computer Number System 43
Converting
base 2 to base 8, 16

•Binary to Octal
•Binary to Hexadecimal

Computer Number System 44


Binary to Octal

Decimal Octal

Binary Hexadecimal

Computer Number System 45


Binary to Octal

• Group bits in threes, starting on right


• Convert to octal digits

Computer Number System 46


Binary to Octal

10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278

Computer Number System 47


Binary to hexadecimal

Decimal Octal

Binary Hexadecimal

Computer Number System 48


Binary to hexadecimal

• Group bits in threes, starting on right


• Convert to octal digits

Computer Number System 49


Binary to hexadecimal

10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16

Computer Number System 50


Converting base 8 to
base 16 and vice versa

•Octal to Hexadecimal
•Hexadecimal to Octal

Computer Number System 51


octal to hexadecimal

Decimal Octal

Binary Hexadecimal

Computer Number System 52


octal to hexadecimal

• Use binary as an intermediary

Computer Number System 53


octal to hexadecimal
10768 = ?16
1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
Computer Number System 54
hexadecimal to octal

Decimal Octal

Binary Hexadecimal

Computer Number System 55


hexadecimal to octal

• Use binary as an intermediary

Computer Number System 56


hexadecimal to octal
1F0C16 = ?8
1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
Computer Number System 57
exercise

Decimal Binary Octal Hexa-decimal

33

1110101

703

1AF

Computer Number System 58


Exercise (ANSWER)

Decimal Binary Octal Hexa-decimal

33 100001 41 21

117 1110101 165 75

451 111000011 703 1C3

431 110101111 657 1AF

Computer Number System 59


Review – multiplying powers

• For common bases, add powers


ab ´ ac = ab+c

26 ´ 210 = 216 = 65,536


or…
26 ´ 210 = 64 ´ 210 = 64k
Computer Number System 60
Binary addition (1 of 2)

• Two 1-bit values


A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Computer Number System 61
Binary addition (2 of 2)

• Two n-bit values 10101


1 1
21
§ Add individual bits
+ 11001 + 25
§ Propagate carries
101110 46
§ E.g.,

Computer Number System 62


Binary multiplication (1 of 3)

• Decimal (review) 35
x 105
175
000
+35 a
3675

Computer Number System 63


Binary 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
Computer Number System 64
Binary multiplication (3 of 3)

• Binary, two n-bit values 1110


• As with decimal values x1011
• E.g., 1110
1110
0000
+1110 a
10011010

Computer Number System 65


fractions

• Decimal to Decimal (review)


• Binary to Decimal
• Decimal to Binary

Computer Number System 66


fractions

• Decimal to Decimal (review)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3 a
3.14

Computer Number System 67


Binary to decimal in fractions

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. a
a2.6875

Computer Number System 68


Decimal to binary in fractions
.14579
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.

Computer Number System 69


exercise

Decimal Binary Octal Hexa-decimal

29.8

101.1101

3.07

C.82

Computer Number System 70


Exercise (ANSWER)

Decimal Binary Octal Hexa-decimal

29.8 11101.110011… 35.63… 1D.CC…

5.8125 101.1101 5.64 5.D

3.109375 11.000111 3.07 3.1C

12.5078125 1100.10000010 14.404 C.82

Computer Number System 71


summary
• There are four common number systems: (1) decimal, (2)
binary, (3) octal, and (4) hexadecimal.
• Binary number system is also called the base-2 system.
• Binary uses only the two digits 0 and 1 which are called
bits.
• Base 8 is convenient shorthand for base 2 numbers.
• One octal digit is equivalent to exactly three binary digits.
• Hexadecimal uses base 16, it has ten symbols 0 through 9
and six additional symbols from A to F.

Computer Number System 72


summary
• To convert binary digits to octal, binary digits are grouped by 3.
• To convert binary digits to hexadecimal binary digits are grouped by 4.
• To convert binary digits to decimal, the number is expanded and
converted to binary
• To convert octal digits to binary, each octal is converted into 3 binary
digits.
• To convert octal digits to hexadecimal, it is converted to binary then to
hexadecimal.
• To convert octal digits to decimal, the number is expanded and
converted to decimal.

Computer Number System 73


summary
• To convert hexadecimal to binary, the hexadecimal digit is
converted to 4 binary digits.
• To convert hexadecimal to octal, it is converted to binary then to
octal.
• To convert hexadecimal to decimal, the number is expanded and
converted to decimal.
• To convert decimal to binary, the number is repeatedly divided by 2
and the remainder is used as an answer.
• To convert decimal to octal, the number is repeatedly divided by 8
and the remainder is used as an answer.
• To convert decimal to hexadecimal, the number is repeatedly
divided by 16 and the remainder is used as an answer.

Computer Number System 74


REFERENCES

Reyes, F. (2005). Introduction to Information


Technology. Rex Book Store
York University. (n.d.). Number Systems

Computer Number System 75

You might also like