Vous êtes sur la page 1sur 32

Number Systems (Representation)

Introduction and Inter-conversion of

–  Binary
“There are 10 types of
–  Octal
people, those who
–  Decimal understand binary and
–  BCD
those who don’t”

–  Hexadecimal

Binary Addition, Subtraction (Complement's method)


Common Number systems

Decimal: -> base10


-> 10 symbols (0,1,2,3,4,5,6,7,8,9)

Binary: -> base2


-> 2 symbols (0,1)

Hexadecimal: -> base16


-> 16 symbols
(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
Decimal Numbers
When we write decimal (base 10) numbers, we use a positional notation system. Each
digit is multiplied by an appropriate power of 10 depending on its position in the number:

For example:
843 = 8 x 102 + 4 x 101 + 3 x 100
= 8 x 100 + 4 x 10 + 3 x 1
= 800 + 40 + 3

For whole numbers, the rightmost digit position is the one’s position (100 = 1). The
numeral in that position indicates how many ones are present in the number.

The next position to the left is ten’s, then hundred’s, thousand’s, and so on. Each digit
position has a weight that is ten times the weight of the position to its right.

In the decimal number system, ten possible values can appear in each digit position,
The decimal numerals are the familiar zero through nine (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

In a positional notation system, the number base is called the radix. Thus, the base ten
system that we normally use has a radix of 10. Thus, in a case where the radix isn’t
understood, decimal numbers would be written like this:

12710 1110 567310


BINARY NUMBER SYSTEM
The binary number system is also a positional notation numbering system, but in this
case, the base is not ten(10), but is instead two(2).

In the binary number system, there are only two possible values (i.e. 0 and 1) that can
appear in each digit position rather than the ten that can appear in a decimal number.

Each digit position in a binary number represents a power of two. So, each binary digit
is multiplied by an appropriate power of 2 based on the position in the number:

For example:
101101 = 1 x 25 + 0 x 24 + 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20
= 1 x 32 + 0 x 16 + 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1
= 32 + 8 + 4 + 1
= 45

The term ‘bit’ is a contraction of the words ‘binary’ and ‘digit’, and the number in the
above example is a 6 bit number.

The following are some additional examples of binary numbers:

1011012 112 101102


Conversion between Binary to Decimal
Converting a number from binary to decimal is quite easy. All that is required is to find
the decimal value of each binary digit position containing a 1 and add them up.

example: to convert 101102 to decimal.


Decimal Hex Binary
10110 0 0 0000
\ \ \___________1 x 21 =2 1 1 0001
\ \_____________1 x 22 =4 2 2 0010
\_______________1 x 24 = 16 3 3 0011
--------- 4 4 0100
22
5 5 0101

example: to convert 110112 to decimal 6 6 0110


11011 7 7 0111
\ \ \ \___________1 x 20 =1 8 8 1000
\ \ \____________1 x 21 =2 9 9 1001
\ \______________1 x 23 = 8 10 A 1010
\________________1 x 24 = 16
11 B 1011
------------------
27 12 C 1100
13 D 1101
14 E 1110
15 F 1111
Conversion between Decimal and Binary
The method for converting a decimal number to binary involves using successive
division by the radix until the dividend reaches 0.

At each division, the remainder provides a digit of the converted number, starting with
the least significant digit.

An example of the process: convert 3710 to binary

37 / 2=18 remainder 1 (least significant digit)

18 / 2 = 9 remainder 0

9 / 2=4 remainder 1

4 / 2=2 remainder 0

2 / 2=1 remainder 0

1 / 2=0 remainder 1 (most significant digit)

The resulting binary number is: 1001012


Conversion between Decimal and Binary

Another example: convert 9310 to binary

93 / 2 = 46 remainder 1 (least significant digit)

46 / 2 = 23 remainder 0

23 / 2 = 11 remainder 1

11 / 2 = 5 remainder 1

5/2=2 remainder 1

2/2=1 remainder 0

1/2=0 remainder 1 (most significant digit)

The resulting binary number is: 1011101


Hexadecimal Numbers
Another number system used in digital systems with base 16 is called hexadecimal, and
each digit position represents a power of 16.

For any number base greater than ten, a problem occurs because there are more than
ten symbols needed to represent the numerals for that number base.

It is customary in these cases to use the ten decimal numerals followed by the letters of
the alphabet beginning with A to provide the needed numerals.

Since the hexadecimal system is base 16, there are sixteen numerals required. The
following are the hexadecimal numerals:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

The following are some examples of hexadecimal numbers:


1016 4716 3FA16 A03F16

The reason for the common use of hexadecimal numbers is the relationship between
the numbers 2 and 16. Sixteen is a power of 2 (16 = 24).

Because of this relationship, four digits in a binary number can be represented with a
single hexadecimal digit. Hence, hexadecimal can be used to write large binary
numbers with much fewer digits.
Hexadecimal Numbers
By using hexadecimal, the numbers can be written with fewer digits and much less likelihood of
error.

To convert a binary number to hexadecimal, divide it into groups of four digits starting with the
rightmost digit.

If the number of digits isn’t a multiple of 4, prefix the number with 0’s so that each group contains
4 digits.

For each four digit group, convert the 4 bit binary number into an equivalent hexadecimal digit.
(See the Binary, BCD, and Hexadecimal Number Tables at the end of this Slide)

For example: Convert the binary number 10110101 to a hexadecimal number

Divide into groups for 4 digits 1011 0101


Convert each group to hex digit i.e. B 5 = B516

Another example: Convert the binary number 0110101110001100 to hexadecimal

Divide into groups of 4 digits 0110 1011 1000 1100 Convert each
group to hex digit 6 B 8 C = 6B8C16
Hexadecimal to Binary Numbers
To convert a hexa-decimal number to a binary number, convert each hexadecimal digit into a
group of 4 binary digits.
Example: Convert the hex number 374F16 into binary
3 7 4 F
Convert the hex digits to binary 0011 0111 0100 1111
00110111010011112
TRY THIS. Convert the following hexadecimal numbers to their decimal equivalents:

(a) 2 4 3 F16

(b) B E E F16

TRY THIS: Convert the following decimal numbers to their hexadecimal equivalents:

(a) 6949810

(b) 11426710
Decimal to Hex

Convert Decimal to hex number: E.g. 250010 = ?????16


Work right to left and keep dividing by 16 and writing down the remainder.

Step1: 2500/16 = 156 remainder 4 = (416)


Step2: 156/16 = 9 remainder 12 = (C16)
Step3: 9/16 =0 remainder 9 = (916 )

ANSWER: 250010 = 9C416

Converting Hex to Decimal E.g. BAD16 = ?????10


keep multiplying by descending power of 16

B A D = B x 162 + A x 161 + D x 160 [160 = 1]


= 11 x 256 + 10 x 16 + 13 x 1
= 298910
Number Systems: EXTRA RESOURCES
Hexadecimal Addition: METHOD 1:
To use this table, simply follow the directions used in this example − Add 4A616 and
1B316. Locate 4, A & 6 in the X column then correspondingly locate 1, B & 3 in the Y
column. The point in 'sum' area where these two columns intersect is the sum of two
numbers.
1) 4A616 + 1B316 = ?????16
1
4 A 616 = 1 1 9 010
+ 1 B 316 = + 4 3 510
------------ ----------------
6 5 916 = 1 6 2 510

2) (B A 3)16 + (5 D E)16 = ????16

1 1 3 + E = 11
BA3 A + D = 17
+5 D E 17 + 1 (carry) = 18
---------------- B + 5 = 10
1181 10 + 1 (carry) = 11

Hence the required sum is 1181 in hexadecimal.


Number Systems: EXTRA RESOURCES
Hexadecimal Addition: METHOD 2:
Use the following steps to perform hexadecimal addition:
1. Add one column at a time.
2. Convert to decimal and add the numbers.
3 (a). If the result of step two is 16 or larger subtract the result from 16 and carry 1 to
the next column.
3 (b). If the result of step two is less than 16, convert the number to hexadecimal.

1 1 1
A C 5 A 9 (9 + 4 = 13 < than 16 hence use ‘D’)
+ B D 6 9 4 (A + 9 = 19 > than OR =16 then 19 – 16 = 3 carry a 1)
--------------------- (1 + 5 + 6 = 12 < than 16 hence use ‘C’)
1 6 9 C 3 D (C + D = 25 > than OR =16 then 25 – 16 = 9 carry a 1)
(1 + A + B = 22 > than OR =16 then 22 – 16 = 6 carry a 1)
(1 + 0 + 0 = 1 < than 16 hence use ‘1’)

TRY:

1DEADDEAFBEEF
+ DADFED2BADBEE
-------------------------------------------
The Octal Number System
The same principles of positional number systems we applied to the decimal and binary
number systems can be applied to the octal number system.

However, the base of the octal number system is eight, so each position of the octal
number represents a successive power of eight.

From right to left, the successive positions of the octal number are weighted 1, 8, 64,
512, etc.

A list of the first several powers of 8 follows:


80 =1 81 =8 82 =64 83 =512 84 =4096 85 =32768

Converting an Octal Number to a Decimal Number


To determine the value of an octal number (3678, for example), we can expand the
number using the positional weights as follows:
3 6 78
\ \ \_________________7 * 80 = 7 * 1 =7
\ \__________________6 * 81 = 6 * 8 = 48
\___________________6 * 82 = 6 * 64 = 192
-----------------
24710
The Octal Number System
Here's another example to determine the value of the octal number 16018:

1 6 0 18
\ \ \_______________ 1 * 80 =1*1 =1
\ \__________________6 * 82 = 6 * 64 = 384
\___________________1 * 83 = 1 * 512 = 512
-------------------
89710

Converting a Decimal Number to an Octal Number


To convert a decimal number to its octal equivalent, the remainder method (the same method
used in converting a decimal number to its binary equivalent) can be used. To review, the
remainder method involves the following four steps:

(1) Divide the decimal number by the base (in the case of octal, divide by 8).

(2) Indicate the remainder to the right.

(3) Continue dividing into each quotient (and indicating the remainder) until the divide
operation produces a zero quotient.

(4) The base 8 number is the numeric remainder reading from the last division to the first
(if you start at the bottom, the answer will read from top to bottom).
The Octal Number System
Example 1: Convert the decimal number 46510 to its octal equivalent:

465 / 8 = 58 remainder 1

58 / 8 = 7 remainder 2

7/8=0 remainder 7

The resulting decimal number is: 721. So, 46510 = 7218

Divide 8 into 465. The quotient is 58 with a remainder of 1; indicate the 1 on the right.

Divide 8 into 58 (the quotient from the previous division). The quotient is 7 with a remainder of 2,
indicated on the right.

Divide 8 into 7. The quotient is 0 with a remainder of 7, as indicated. Since the quotient is 0, stop
here.

The answer, reading the remainders from top to bottom, is 721, so 46510 = 7218
Binary to Octal / Octal to Binary
Binary to Octal
Step 1 - Divide the binary digits into groups of three (starting from the right).
Step 2 - Convert each group of three binary digits to one octal digit.

Example: Binary Number : 101012 = ?????8


Step 1: 101012 = 010 101
Step 2: 101012 = 28 58
Step 3: 101012 = 258

Binary Number : 101012 = Octal Number : 258

Octal to Binary
Step 1 - Convert each octal digit to a 3 digit binary number (the octal digits may be
treated as decimal for this conversion).
Step 2 - Combine all the resulting binary groups into a single binary number.

Example: Octal Number : 258 = ?????2


Step 1: 258 = 210 510
Step 2: 258 = 0102 1012
Step 3: 258 = 0101012

Octal Number : 258 = Binary Number : 101012


Decimal to Octal
Example 2: Convert the decimal number 254810 to its octal equivalent:

2458 / 8 = 318 remainder 4

318 / 8 = remainder 6

?/8=? remainder ?

?/8=? remainder ?

?/8=? remainder ?

The resulting decimal number is: 721. So, 254810 = ?8

TRY THIS: Convert the following decimal to octal and equivalent octal to binary:
(a) 300210

(b) 651210
Binary Addition
Binary Addition
Binary Addition

It is a key for binary subtraction, multiplication, division. There four rules of the binary
addition.

In fourth case, a binary addition is creating a sum of (1+1=10) i.e. 0 is write in the given
column and a carry of 1 over to the next column.

Example – Addition 0011010 + 001100 = 00100110

11 CARRY
0011010 = 2610
+ 0001100 = 1210
--------------------------------------------
0100110 = 3810
Binary Subtraction
Subtraction and Borrow, these two words will be used very frequently for the binary
subtraction. There are four rules of the binary subtration

Example – Subtraction 0011010 - 001100 = 00001110

01
01 BORROW
0011010 = 2610
- 0001100 = 1210
--------------------------------------------
0001110 = 1410
Binary Subtraction
Subtract 19 from 6.

0000 0110 6
−0001 0011 19
============== ====
11111 0011 −12 — An end-around borrow is produced, and the sign bit of
the intermediate result is 1.
−0000 0001 1 — Subtract the end-around borrow from the result.
============== ====
1111 0010 −13 — The correct result (6 − 19 = -13)

Subtract −3 from 19.

00010011 19
−11111100 −3
============== ====
10001 0111 23 — An end-around borrow is produced.
−0000 0001 1 — Subtract the end-around borrow from the result.
============== ====
0001 0110 22 — The correct result (19 − (−3) = 22).
COMPLIMENTS
Binary system complements

As the binary system has base radix, r = 2. So the two types of complements for the
binary system are 2's complement and 1's complement.

1's complement
The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's.
This is called as taking complement or 1's complement. Example of 1's Complement is
as follows.
2’s Compliment

The 2's complement of binary number is obtained by adding 1 to the Least Significant
Bit (LSB) of 1's complement of the number.

2's complement = 1's complement + 1

Example of 2's Complement is as follows.


2’s Compliment
For example: Find the 2’s complement of the 8 bit number '0 0 1 0 1 0 0 1'

11010110 First, invert the bits


+ 00000001 Then, add 1
--------------------------------
= 11010111

The 2’s complement of '0 0 1 01 0 0 1' is '1 1 0 1 0 1 1 1'

TRY THIS: Find the 2’s complement of the following numbers

(a) 10110101

(b) 1010101010111111
Addition and Subtraction using 1's and 2's complement
Let's consider problem of subtracting 110 = 00012 from 710 = 01112 using 1's
complement.

First, we need to convert 00012 to its negative equivalent in 1's complement.


0111 (7)
- 0 0 0 1 - (1)

To do this we change all the 1's to 0's and 0's to 1's. Notice that the most-significant digit
is now 1 since the number is negative. 0001 → 1110

Next, we add the negative value we computed to 01112. This gives us


0111 (7)
+1110 + (-1)
-------------------------
10101 (6)

Notice that our addition caused an overflow bit. Whenever we have an overflow bit in 1's
complement, we add this bit to our sum to get the correct answer. If there is no overflow
bit, then we leave the sum as it is.
0101
+ 1
-----------
0 1 1 0 (6) This gives us a final answer of 01102 (or 610).
Addition and Subtraction using 1's and 2's complement
Now let's look at problem that does not generate an overflow bit. We will subtract 710
from 110 using 1's complement. First, we state our problem in binary.
0001 (1)
-0111 - (7)

Next, we convert 01112 to its negative equivalent and add this to 00012.
0001 (1)
+1000 +(-7)
--------------------------
1001 (-6)

This time our results does not cause an overflow, so we do not need to adjust the sum.
Notice that our final answer is a negative number since it begins with a 1. Remember
that our answer is in 1's complement notation so the correct decimal value for our
answer is -610 and not 910.

0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110

-0 = 1111 -1 = 1110 -2 = 1101 -3 = 1100 -4 = 1011 -5 = 1010 -6 = 1001


Addition and Subtraction using 1's and 2's complement
2's Complement Addition
Two's complement addition follows the same rules as binary addition.

For example, 5 + (-3) = 2 0101 0000 0101 = +5


+ 1111 1101 = -3
3 = 0011 ------------------------------------------------
1's complement -3 = 1100 1 0 0 0 0 0 0 1 0 = +2
2's complement = 1100 + 0001 = 1101

Then discard the carry (indicates overflow), and you have your result: 0000 0010 which
equals to 2 as expected.

2's Complement Subtraction


adding a negative number is the same as subtracting a positive one.

For example, 7 - 12 = (-5) 0 0 0 0 0 1 1 1 = +7


+ 1 1 1 1 0 1 0 0 = -12
-----------------------------------------------
1 1 1 1 1 0 1 1 = -5
12 = 0000 1100
-12 = 1111 0011 + 0000 0001 = 1111 0100
- 5 = 0000 0101 = 1111 1010 + 0000 0001 = 1111 1011
UNIT 1.5 : Number Systems
TRY THIS: Substraction using 1's and 2's complement

(a) 10 -8

(b) 11- 17

(c) 23 – 89

(d) 22 - 22
UNIT 1.5 : Number Systems
Powers of 2:

20 ......................1
21 ......................2
22 ......................4
23 ......................8
24 ....................16
25 ....................32
26 ....................64
27 ..................128
28 ..................256
29 ..................512
210 ................ 1024
211 ................ 2048
212 ................ 4096
213 ................ 8192
214 .............. 16384
215 .............. 32768
216 .............. 65536
UNIT 1.5 : Number Systems
Hexadecimal Digits

0 ...................... 0 0000
1 ...................... 1 0001
2 ...................... 2 0010
3 ...................... 3 0011
4 ...................... 4 0100
5 ...................... 5 0101
6 ...................... 6 0110
7 ...................... 7 0111
8 ...................... 8 1000
9 ...................... 9 1001
10 ..................... A 1010
11 ..................... B 1011
12 ..................... C 1100
13 ..................... D 1101
14 ..................... E 1110
15 ......................F 1111
Equivalent Numbers in Decimal, Binary and Hexadecimal Notation:
UNIT 1.5 : Number Systems
TRY THIS: Convert the following numbers to their decimal equivalents:

(a) 1 1 0 0 1 1 02

(b) 1 1 1 1 1 0 0 12
(c) 4910

(d) 2110

(e) 5 68

(f) 11638