You are on page 1of 40

Number

Systems
Introduction

Although today's programming


environments are becoming
increasingly visual and graphic,
numbers are still at the root of
everything a computer does. It may
look like a textbox, icon, or sound like
a WAV file, but it's really just numbers.
And, in fact, it's really just binary
numbers.
Introduction

The representation of values using


different number systems is a
cornerstone in the understanding of
the modern computer.
Decimal Number System

• The word "Decimal" means "based on 10"


(From Latin decima: a tenth part).
• Uses numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
that's 10 numbers. Hence base 10. Radix
is another name for base 10.
• Examples:
– 891110
– 4510
– 8796510
Binary Number System

• Binary numbering is the number system


that is used by computers.
• The word binary comes from "Bi-" meaning
two. We see "bi-" in words such as
"bicycle" (two wheels) or "binocular" (two
eyes).
• It is made up of only 0s and 1s.
• A single binary digit (like "0" or "1") is called
a "bit". For example 11010 is five bits long.
Binary Number System

• The word bit is made up from the words


"binary digit“.
• Examples:
– 10012
– 1001112
– 111112
Octal Number System

• The Octal system is based on the binary


system with a 3-bit boundary.
• The Octal Number System uses base 8.
– includes only the digits 0 through 7 (any other
digit would make the number an invalid octal
number)
• Examples:
– 10048
– 76548
Hexadecimal Number System

• The Hexadecimal Number System uses


base 16.
• Includes only the digits 0 through 9 and the
letters A, B, C, D, E, and F

• Examples:
– A416
– 107H16
– 12B16
CONVERSION

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

There are two ways to convert decimal


numbers into binary.
• Method 1
Comparison with descending powers of two
and subtraction
• Method 2
Short division by two with remainder
Method 1 Steps

1. List the powers of two in a "base 2 table"


from right to left. Start at 20, evaluating it
as "1". Increment the exponent by one for
each power. It would look like this:
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
28 29
256 512
For this example, let's convert the decimal
number 2910 to binary.

2. Select the biggest position value that is not


greater than your chosen number
– What is the greatest power of two that will fit
into 29?
• in this case 16 is the largest value

16 8 4 2 1
3. Since 16 fits, write a 1 for the leftmost
binary digit, and subtract 16 from your
decimal number, 29. 29 -16 = 13
24 23 22 21 20
16 8 4 2 1
1
4. Move to the next lower power of two. Can
13 fit into 8? Yes, So write a 1, and
subtract 8 from 13. 13 - 8 = 5
24 23 22 21 20
16 8 4 2 1
1 1
5. Move to the next lower power of two. Can
5 fit into 4? Yes, So write a 1, and
subtract 5 from 4. 5 - 4 = 1
24 23 22 21 20
16 8 4 2 1
1 1 1
6. Move to the next lower power of two. Can
1 fit into 2? No, So write a 0.
24 23 22 21 20
16 8 4 2 1
1 1 1 0
7. Move to the next lower power of two. Can
1 fit into 1? Yes, So write a 1, and
subtract 1 from 1. 1-1 = 0
24 23 22 21 20
16 8 4 2 1
1 1 1 0 1

FINAL ANSWER : 2910 = 111012


Method 2 Steps
Let's convert the decimal number 2910 to
binary.
1. Write the decimal number as the dividend
and write the base of the destination
system (in our case, "2" for binary) as the
divisor. 29 / 2 = 14 r. 1
2. Continue downwards, dividing each new
quotient by two and writing the remainders
to the right of each dividend.
29 / 2 = 14 r. 1
14 / 2 = 7 r. 0
7/2 = 3 r. 1
3/2 = 1 r. 1
1/2 = 0 r. 1
Starting with the bottom 1, read the sequence
of 1's and 0's upwards to the top. You should
have 10011100.
FINAL ANSWER : 2910 = 111012
Decimal to Octal

To convert decimal to octal is slightly more


difficult.

The typical method to convert from decimal


to octal is repeated division by 8.

While we may also use repeated subtraction


by the weighted position value, it is more
difficult for large decimal numbers.
Decimal to Octal

Let's convert the decimal number 17710 to


octal.
1. Write the decimal number as the dividend
and write the base of the destination
system (in our case, “8" for octal) as the
divisor. 177 / 8 = 22 r. 1
2. Continue downwards, dividing each new
quotient by eight and writing the
remainders to the right of each dividend.
Stop when the quotient is 0.
177 / 8 = 22 r. 1
22 / 8 = 2 r. 6
2/8 = 0 r. 2
The answer is read from bottom to top. You
should have 261.

FINAL ANSWER : 17710 = 2618


Decimal to Hexadecimal

To convert decimal to hex is slightly more


difficult.

The typical method to convert from decimal


to hex is repeated division by 16.

While we may also use repeated subtraction


by the weighted position value, it is more
difficult for large decimal numbers.
Decimal to Hexadecimal

Let's convert the decimal number 476810 to


hexadecimal.
1. Write the decimal number as the dividend
and write the base of the destination
system ( “16" for hexadecimal) as the
divisor. 4768 / 16 = 298 r. 0
2. Continue downwards, dividing each new
quotient by sixteen and writing the
remainders to the right of each dividend.
Stop when the quotient is 0.
4768 / 16 = 298 r. 0
298 / 16 = 18 r. 10 = A
18 / 16 = 1 r. 2
1 / 16 = 0 r. 1
The answer is read from bottom to top. You
should have 12A0.

FINAL ANSWER : 4768 10 = 12A016


CONVERSION

Binary to Decimal
Binary to Octal
Binary to Hexadecimal
Binary to Decimal
Converting binary to decimal is very simple.

1. Write the exponential expressions


("powers of two") that represent each
placeholder (from right to left)
Example: 11002 to decimal number
23 22 21 20
1 1 0 0
Binary to Decimal
2. Multiply each expression by 1 or 0.
23 22 21 20
1 1 0 0
8*1 4*1 2*0 1*0
8 4 0 0
3. Add all the products/answers.
8+4+0+0 = 12
FINAL ANSWER : 11002 = 1210
Binary to Octal
To convert binary to octal, simply use
grouping.

1. Group the binary numbers into 3 digits per


group starting from right to left.
Example: 11101012
1110101
Binary to Octal
2. Assign the position value of each digit per
group. Start from right to left.
Example: 11101012
1 4 2 1 4 2 1
1 1 1 0 1 0 1
3. Multiply each binary number to its position
value.
1 1 1 0 1 0 1
1*1 1*4 1*2 0*1 1*4 0*2 1*1
Binary to Octal
4. Add all the products/answers per group.
1 1 1 0 1 0 1
1*1 1*4 1*2 0*1 1*4 0*2 1*1
1 4 + 2+0 4 + 0 +1

FINAL ANSWER : 11101012 = 1658


Binary to Hexadecimal
To convert binary to hexadecimal, simply use
grouping.

1. Group the binary numbers into 4 digits per


group starting from right to left.
Example: 111010112
1 1 1 0 1 0 11
Binary to Hexadecimal
2. Assign the position value of each digit per
group. Start from right to left.
Example: 111010112
8 4 2 1 8 4 2 1
1 1 1 0 1 0 11
3. Multiply each binary number to its position
value.
1 1 1 0 1 0 1 1
1*8 1*4 1*2 0*1 1*8 0*2 1*1 1*1
Binary to Hexadecimal
4. Add all the products/answers per group.
1 1 1 0 1 0 1 1
1*8 1*4 1*2 0*1 1*8 0*4 1*2 1*1
8+4+1+0 8+0+2+1
14=E 11=B
FINAL ANSWER : 111010112 = EB16
CONVERSION

Octal to Decimal
Octal to Binary
Octal to Hexadecimal
Octal to Decimal
1. List the powers of eight in a "base 8 table"
from right to left. Start at 80, evaluating it
as "1". Increment the exponent by one for
each power. It would look like this:
84 83 82 81 80
4096 512 64 8 1
Example: 1278
82 81 80
1 2 7
Octal to Decimal
2. Multiply the value in each position by its
Octal weight and add each value.
82 81 80
1 2 7
1*64 2*8 7*1
64+16+7 = 87

FINAL ANSWER : 1278 = 8710


Octal to Binary
1. To convert octal to binary, write the
corresponding three-digit binary-coded
octal equivalent in each octal digit.
Example: 6538
6 5 3
110 101 011
2. Combine the 3-bit sections by removing
the spaces.
FINAL ANSWER : 6538 = 1101010112
CONVERSION

Hexadecimal to Decimal
Hexadecimal to Binary
Hexadecimal to Octal
Hexadecimal to Decimal
1. List the powers of eight in a "base 16
table" from right to left. Start at 160,
evaluating it as "1". Increment the
exponent by one for each power. It would
look like this:
163 162 161 160
4096 256 16 1
Example: B6E16
162 161 160
B 6 E
Hexadecimal to Decimal
2. Multiply the value in each position by its
Octal weight and add each value.
162 161 160
B 6 E
11*256 6*16 14*1
2816 + 96 + 14 = 2926

FINAL ANSWER : B6E16 = 292610


Hexadecimal to Binary
1. To convert hex to binary, write the
corresponding four-digit binary-coded hex
equivalent in each hex digit.
Example: ABC16
A B C
1010 1011 1100
2. Combine the 4-bit sections by removing
the spaces.
FINAL ANSWER : ABC16 = 1010101111002

You might also like