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

1 Number Systems

Uploaded by

govindlanghani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

1 Number Systems

Uploaded by

govindlanghani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 119

Number Systems

Objectives
Understand why computers use binary (Base-2)
numbering.
Understand how to convert Base-2 numbers to Base-
10 or Base-8.
Understand how to convert Base-8 numbers to Base-
10 or Base 2.
Understand how to convert Base-16 numbers to Base-
10, Base 2 or Base-8.
Why Binary System?

• Computers are made of a series of


switches
• Each switch has two states: ON or OFF
• Each state can be represented by a number
– 1 for “ON” and 0 for “OFF”
Converting Base-2 to Base-10
(1 0 0 1 1)
2

OFF

OFF
ON

ON

ON
Exponent:

Calculation:16 0 0 2 1
+ + + + =

(19)10
Number systems include decimal, binary, octal
and hexadecimal

Number System Base Symbol


Binary Base 2 B
Octal Base 8 O
Decimal Base 10 D
Hexadecimal Base 16 H
1.1 Decimal Number System
• The Decimal Number System uses base 10. It
includes the digits {0, 1,2,…, 9}. The weighted
values for each position are:
Base

10^4 10^3 10^2 10^1 10^0 10^-1 10^-2 10^-3

10000 1000 100 10 1 0.1 0.01 0.001

left of the decimal point Right of decimal point


6
• Each digit appearing to the left of the decimal
point represents a value between zero and nine
times power of ten represented by its position in
the number.
• Digits appearing to the right of the decimal point
represent a value between zero and nine times an
increasing negative power of ten.
• Example: the value 725.194 is represented in
expansion form as follows:
• 7 * 10^2 + 2 * 10^1 + 5 * 10^0 + 1 * 10^-1 + 9 *
10^-2 + 4 * 10^-3
• =7 * 100 + 2 * 10 + 5 * 1 + 1 * 0.1 + 9 * 0.01 + 4 *
0.001
• =700 + 20 + 5 + 0.1 + 0.09 + 0.004
• =725.194
1.2 The Binary Number Base

Systems
Most modern computer system using binary logic. The
computer represents values(0,1) using two voltage levels
(usually 0V for logic 0 and either +3.3 V or +5V for logic
1).
• The Binary Number System uses base 2 includes only the
digits 0 and 1
• The weighted values for each position are : Base

2^5 2^4 2^3 2^2 2^1 2^0 2^-1 2^-2

32 16 8 4 2 1 0.5 0.25
1.3 Number Base Conversion
• Binary to Decimal: multiply each digit by its
weighted position, and add each of the weighted
values together or use expansion formdirectly.
• Example the binary value 1100 1010 represents :
• 1*2^7 + 1*2^6 + 0*2^5 + 0*2^4 + 1*2^3 + 0*2^2 +
1*2^1 + 0*2^0 =
• 1 * 128 + 1 * 64 + 0 * 32 + 0 * 16 + 1 * 8 + 0 * 4 + 1 *
2+0*1=
• 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 =202
• Decimal to Binary
There are two methods, that may be used to convert
from integer number in decimal form to binaryform:
1-Repeated Division By 2
• For this method, divide the decimal number by 2,
• If the remainder is 0, on the right side write down a 0.
• If the remainder is 1, write down a 1.
• When performing the division, the remainders which
will represent the binary equivalent of the decimal
number are written beginning at the least significant
digit (right) and each new digit is written to more
significant digit (the left) of the previous digit.
• Example: convert the number 333 to binary.
Division Quotient Remainder Binary
333/2 166 1 1
166/2 83 0 01
83/2 41 1 101
41/2 20 1 1101
20/2 10 0 01101
10/2 5 0 001101
5/2 2 1 1001101
2/2 1 0 01001101
1/2 0 1 101001101
Octal System
 Computer scientists are often looking for
shortcuts to do things
 One of the ways in which we can represent
binary numbers is to use their octal
equivalents instead
 This is especially helpful when we have to do
fairly complicated tasks using numbers
• The octal numbering system includes
eight base digits (0-7)
• After 7, the next placeholder to the right
begins with a “1”
• 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 ...
Octal Placeholders
Number: 2 4 1
“Sixty-
Fours”

“Eights”


“Ones
Placeholder
Name:

Value: 64*2 8*4 1*1


Exponential
Expression: 82*2 81*4 80*1
Transform (44978)10 to Octal
Division Quotient Remainder Binary
• .
44978 / 8 5622 2 2
5622 / 8 702 6 62
702/8 87 6 662
87/8 10 7 7662
10/8 1 2 27662
1/8 0 1 127662
Common Number Systems
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
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Hexa-
Decimal Binary Octal 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
Hexa-
Decimal Binary Octal 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
Hexa-
Decimal Binary Octal 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
Conversion Among Bases
• The possibilities:

Decimal Octal

Binary Hexadecimal
2510 = 110012 = 318 = 1916

Base
Decimal Octal

Binary Hexadecimal
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 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
Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Octal to Decimal

Decimal Octal

Binary Hexadecimal
Octal to Decimal
• Technique
– 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
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 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
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
• 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
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
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
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
33
1110101
703
1AF

Don’t use a calculator!


Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Common Powers (1 of 2)
• Base 10 Power Preface Symbol Value
10-12 pico p .000000000001

10-9 nano n .000000001

10-6 micro µ .000001

10-3 milli m .001

103 kilo k 1000

106 mega M 1000000

109 giga G 1000000000


1012 tera T 1000000000000
Common Powers (2 of 2)
• Base 2 Power Preface Symbol Value
210 kilo k 1024

220 mega M 1048576

230 Giga G 1073741824

• What is the value of “k”, “M”, and “G”?


• In computing, particularly w.r.t. memory,
the base-2 interpretation generally applies
Example
In the lab…
1. Double click on My Computer
2. Right click on C:
3. Click on Properties

/ 230 =
Exercise – Free Space
• Determine the “free space” on all drives on a
machine in the lab
Free space
Drive Bytes GB
A:
C:
D:
E:
etc.
Review – multiplying powers
• For common bases, add powers
ab × ac = ab+c

26 × 210 = 216 = 65,536


or…
26 × 210 = 64 × 210 = 64k
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”
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
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
• Decimal to binary x
.14579
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!
Hexa-
Decimal Binary Octal 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
Numbers

Natural Numbers
Zero and any number obtained by repeatedly adding
one to it.

Examples: 100, 0, 45645, 32

Negative Numbers
A value less than 0, with a – sign

Examples: -24, -1, -45645, -32

2
Numbers

Integers
A natural number, a negative number, zero

Examples: 249, 0, - 45645, - 32

Rational Numbers
An integer or the quotient of two integers

Examples: -249, -1, 0, 3/7, -2/5

3
Natural Numbers

642 is 600 + 40 + 2 in BASE 10

The base of a number determines the number


of digits and the value of digit positions

5
Positional Notation

Continuing with our example…


642 in base 10 positional notation is:

6 x 102 = 6 x 100 = 600


+ 4 x 101 = 4 x 10 = 40
+ 2 x 10º = 2 x 1 = 2 = 642 in base 10

The power indicates


This number is in the position of
base 10 the number
6
Positional Notation
R is the base
of the number
As a formula:

dn * Rn-1 + dn-1 * Rn-2 + ... + d2 * R + d1

n is the number of d is the digit in the


digits in the number ith position
in the number

642 is 63 * 102 + 42 * 10 + 21

7
Positional Notation

What if 642 has the base of 13?

+ 6 x 132 = 6 x 169 = 1014


+ 4 x 131 = 4 x 13 = 52
+ 2 x 13º = 2 x 1 = 2
= 1068 in base 10

642 in base 13 is equivalent to 1068


in base 10

8
6
Binary

Decimal is base 10 and has 10 digits:


0,1,2,3,4,5,6,7,8,9

Binary is base 2 and has 2 digits:


0,1
For a number to exist in a given base, it can only contain the
digits in that base, which range from 0 up to (but not including)
the base.

What bases can these numbers be in? 122, 198, 178, G1A4

9
Bases Higher than 10

How are digits in bases higher than 10


represented?

With distinct symbols for 10 and above.

Base 16 has 16 digits:


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

10
Converting Octal to Decimal

What is the decimal equivalent of the octal


number 642?

6 x 82 = 6 x 64 = 384
+ 4 x 81 = 4 x 8 = 32
+ 2 x 8º = 2 x 1 = 2
= 418 in base 10

11
Converting Hexadecimal to
Decimal
What is the decimal equivalent of the
hexadecimal number DEF?

D x 162 = 13 x 256 = 3328


+ E x 161 = 14 x 16 = 224
+ F x 16º = 15 x 1 = 15
= 3567 in base 10

Remember, the digits in base 16 are


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

What is the decimal equivalent of the binary


number 1101110?
1 x 26 = 1 x 64 = 64
+ 1 x 25 = 1 x 32 = 32
+ 0 x 24 = 0 x 16 =0
+ 1 x 23 = 1x8 =8
+ 1 x 22 = 1x4 =4
+ 1 x 21 = 1x2 =2
+ 0 x 2º = 0x1 =0
= 110 in base 10

13
Arithmetic in Binary
Remember that there are only 2 digits in binary,
0 and 1

1 + 1 is 0 with a carry

Carry Values
111111
1010111
+1 0 0 1 0 1 1
10100010

14
Subtracting Binary Numbers

Remember borrowing? Apply that concept


here:

12
202
1010111
- 111011
0011100

15
Counting in Binary/Octal/Decimal
Converting Binary to Octal

• Mark groups of three (from right)


• Convert each group

10101011 10 101 011


2 5 3

10101011 is 253 in base 8

17
Converting Binary to Hexadecimal

• Mark groups of four (from right)


• Convert each group

10101011 1010 1011


A B

10101011 is AB in base 16

18
Binary Numbers and Computers

Computers have storage units called binary digits or


bits

Low Voltage = 0
High Voltage = 1 all bits have 0 or 1

22
Converting Binary to Octal
start
100011001010012
STEP ONE: Take the binary number and
from right to left, group all placeholders in
triplets. Add leading zeros, if necessary:

010 001 100 101 001


0010 001 100 101 0012 = 214518

STEP TWO: Convert each triplet to its


single-digit octal equivalent. (HI NT: For
each triplet, the octal conversion is the
same as converting to a decimal number):
010 001 100 101 001
2 1 4 5 1
Converting Octal to Binary

435208 = 1000111010100002
STEP ONE: Take each octal digit and
convert each digit to a binary triplet. Keep
leading zeros:
4 3 5 2 0
100 011
0 101 010
0 000
Hexadecimal System
• Sometimes, it is necessary to use a numbering
system that has more than ten base digits
• One such numbering system, hexadecimal, is
useful on the Web
• Hexadecimal number, a Base-16 numbering
system, is used in specifying web colors
Hexadecimal Numbering
 There are new symbols for the Base-16 equivalents
of the Base-10 numbers 10, 11, 12, 14 and 15.
Examine:
DEC 0 1 2 3 4 5 6 7

HEX 0 1 2 3 4 5 6 7

DEC 8 9 10 11 12 13 14 15

HEX 8 9 A B C D E F
Decimal Hexadecimal Octal Binary
0 0 0 0000
1 1 1 0001
2 2 2 0010
3 3 3 0011
4 4 4 0100
5 5 5 0101
6 6 6 0110
7 7 7 0111
8 8 10 1000
9 9 11 1001
Decimal Hexadecimal Octal Binary

10 A 12 1010

11 B 13 1011

12 C 14 1100

13 D 15 1101

14 E 16 1110

15 F 17 1111
• Convert a hexadecimal number to a binary
number,
• simply divided the binary number into 4-bit
groups
• substitute the corresponding four bits in
binary for each hexadecimal digit in the
number.
• For example, convert ABCD to a binary value,
The binary equivalent is:
• ABCD= 1010 1011 1100 1101
• Binary to Hex Conversion
• Break the binary number into 4-bit groups from
the Left to the right.
• Convert the 4-bit binary number to its Hex
equivalent.
• For example, the binary value 101011111011
0010 will be written:
• 1010 1111 1011 0010=AFB2
• Hex to Binary Conversion
• Convert the Hex number to its 4-bit binary
equivalent.
• Combine the 4-bit groups by removing the
spaces.
• For example, the hex value AFC7 will be
written:
• AFC7=1010 1111 1110 0111
• To convert from Hex to Decimal,
• multiply the value in each position by its hex
weight and
• add each value. use the expansion form
• AFB.2=10*163 +15*162 +11*16+2*16-1
Decimal to Hex Conversion
• Repeated Division By 16
• Divide the decimal number by 16, and write the
remainder on the side as the least significant digit.
• This process is continued by dividing the quotient by
16 and writing the remainder until the quotient is 0.
• the remainders represent the hex equivalent of the
decimal number are written beginning at the least
significant digit (right) and each new digit is written
to the next more significant digit (the left) of the
previous digit.
Example convert 196710 to Hex

Division Quotient Remainder Hex Number

1967/16 122 15 F

122/16 7 10 AF

7/16 0 7 7AF

Then (1967)10 =(7AF)16


Decimal fraction to B, O and H
Fraction Product with New farction integer
Base
0.0625 2X0.0625 0.1250 .0

0.1250 2X0.125 0.250 .00

0.250 2X0.25 0.5 .000

0.5 2X0.25 1.0 .0001

0.062510 = .00012
Fraction Product with New fraction integer
Base
0.0625 8X0.0625 0.5000 .0
0.5 8X0.5 4. 0 .04
0.062510 = .048

Fraction Product with New fraction integer


Base
0.0625 16X0.0625 1.0000 .1

0.062510 = .116
Convert (1967.0626)10 to B,O,H
Division Quotient Remainder Hex Number

1967/8 245 7 7

245/8 30 3 37

30/8 3 6 376

3/8 0 3 3637

(1967)10= (3537)8 0.062510 = .048

(1967.0626)10= (3637.04)8
Binary Addition
+ 0 1
• 0+0=0
• 0+1=1
• 1+0=1
0 0 1
• 1 + 1 = 10
1 1 10
Multiply Binary numbers

* 0 1
 0*0=0
 0*1=0
 1*0=0
0 0 0
 1*1=1
1 0 1
– 1111 carry 1 1 1 (carry)
–111101 01101
1 0 1 1 1+
100111+ -------------
• 1100100 100100
Multiply 1011 and 1010

– 1 0 1 1
×1 0 1 0
---------------
0 0 0 0
1 0 1 1
0 0 0 0
+1 0 1 1
------------------
1 1 01 1 1 0
Multiply Example

1 1 0 1 1 1
1 1 1
1 1 0 1 1 1
1 1 0 1 1 1
1 1 0 1 1 1
------------------------------------
1 0 1 1 1 1 0 1 1
Characteristics of Numbering Systems
1) The digits are consecutive.
2) The number of digits is equal to the size of the
base.
3) Zero is always the first digit.
4) The base number is never a digit.
5) When 1 is added to the largest digit, a sum of zero
and a carry of one results.
6) Numeric values are determined by the implicit
positional values of the digits.
Multiplication Algorithm
Convert (10101101)2 to its decimal equivalent:

Binary 1 0 1 0 1 1 0 1

Positional Values x x x x x x x x
27 26 25 24 23 22 21 20
Products 128 + 32 + 8 + 4 + 1

17310
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
Hexadecimal to Decimal Conversion
Convert 3B4F16 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
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

You might also like