Você está na página 1de 57

Number Systems and Binary Arithmetic

Introduction to Numbering Systems


We are all familiar with the decimal number system (Base 10). Some other number systems that we will work with are:
Binary p Base 2 Octal p Base 8 Hexadecimal p Base 16

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 determined by the have implicit positional values of the digits.

Significant Digits
Binary: 11101101
Most significant digit Least significant digit

Hexadecimal: 1D63A7A
Most significant digit Least significant digit

Common Number Systems


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

Binary Number System


Also called the 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

Notations used in digital systems:


4 bits = Nibble 8 bits = Byte 16 bits = Word 32 bits = Double word 64 bits = Quad Word (or paragraph)

Binary Numbering Scale


Base 2 Number Base 10 Equivalent Power Positional Value

000 001 010 011 100 101 110 111

0 1 2 3 4 5 6 7

20 21 22 23 24 25 26 27

1 2 4 8 16 32 64 128

Hexadecimal and Octal


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

Octal
1 2 3 4 5 6 7 10 11 12 13 14 15 16 17

Decimal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Binary
0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Weighted Positional Notation


Use the position of the symbol to indicate the value By assigning each position at the appropriate power of the base, we can get a unique representation of numbers in that base Decimal System (Base 10)
Given a sequence of n digits d0,d1, ,dn-1 dn-1.10n-1 + + d1.101 + d0.100

Weight

12510 =>

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

Base

Octal Number System


Also known as the Base 8 System Uses digits 0 - 7 Readily converts to binary Groups of three (binary) digits can be used to represent each octal digit Also uses multiplication and division algorithms for conversion to and from base 10

Hexadecimal Number System


Base 16 system Uses digits 0-9 & letters A,B,C,D,E,F Groups of four bits represent each base 16 digit

Quick Example

2510 = 110012 = 318 = 1916


Base

Binary to Decimal Conversion


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

Multiplication Algorithm
Convert (10101101)2 to its decimal equivalent:

Binary Positional Values


Products

1 0 1 0 1 1 0 1 x x x x x x x x
27 26 25 24 23 22 128 + 32 + 8 + 4 + 1 21 20

17310

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 1 x 20 = 1 x 21 0 x 22 1 x 23 0 x 24 1 x 25

1010112 =>

1 = 2 = 0 = 8 = 0 = 32 4310

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

Octal to Decimal Conversion


Convert 6538 to its decimal equivalent:
Octal Digits Positional Values

6
x

82
Products

81

80

384 + 40 + 3

42710

Example

7248 => 4 x 80 = 2 x 81 = 7 x 82 =

4 16 448 46810

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

Hexadecimal to Decimal Conversion


Convert 3B4F16 to its decimal equivalent:
Hex Digits

3
Positional Values x

B
x

F
x

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

Exercises
Convert the following to decimal: 1.1001102 2.3E16 3.1416 4.3528 5.4D316 6.3F53A16 7.74738 8.557C16

Binary to Octal
Technique
Group bits in threes, starting on right Convert to octal digits

Substitution Code
Substitution code can also be used to convert binary to octal by using 3-bit groupings: 2 5 5 2 7 1 5 2

010 101 101 010 111 001 101 010

255271528

Example
10110101112 = ?8

1 011 010 111

10110101112 = 13278

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

Binary to Hexadecimal
Technique
Group bits in fours, starting on right Convert to hexadecimal digits

Substitution Code
Convert 0101011010101110011010102 to hex using the 4-bit substitution code : 5 6 A E 6 A

0101 0110 1010 1110 0110 1010

56AE6A16

Example
10101110112 = ?16

10 1011 1011

10101110112 = 2BB16

Exercises
Convert 11101 to octal Convert 11101 to hexadecimal Convert 100110 to octal Convert 11001100 to hexadecimal _________ _________ _________ _________

Convert Binary to Decimal, Octal and Hexadecimal: 11101101 111100111 10111001 10010110 1111001 11011101 10011110 100010011 101011110 11100001

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 quotient and remainder
The remainder digits (a sequence of zeros and ones) form the binary equivalent in least significant to most significant digit sequence

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.

Division Algorithm
Convert 67 to its binary equivalent:
6710 = x2
Step 1: 67 / 2 = 33 R 1 Step 2: 33 / 2 = 16 R 1 Step 3: 16 / 2 = 8 R 0 Step 4: 8 / 2 = 4 R 0 Step 5: 4 / 2 = 2 R 0 Step 6: 2 / 2 = 1 R 0 Step 7: 1 / 2 = 0 R 1 Divide 67 by 2. Record quotient in next row Again divide by 2; record quotient in next row Repeat again Repeat again Repeat again Repeat again STOP when quotient equals 0

1 0 0 0 0 1 12

Example
12510 = ?2 2 125 2 62 2 2 2 2 2 31 15 7 3 1 0 1 0 1 1 1 1 1

12510 = 11111012

Decimal to Octal
Technique
Divide by 8 Keep track of the remainder

Example
123410 = ?8 8 8 8 8 1234 154 19 2 0

2 2 3 2

123410 = 23228

Decimal to Octal Conversion


Convert 42710 to its octal equivalent:
427 / 8 = 53 R3 53 / 8 = 6 R5 6 / 8 = 0 R6 Divide by 8; R is LSD Divide Q by 8; R is next digit Repeat until Q = 0

6538

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 3 / 16 = 0 R3

= E in Hex

33E16

Example
123410 = ?16 16 16 16 1234 77 4 0

2 13 = D 4

123410 = 4D216

Octal to Binary
Technique
Convert each octal digit to a 3-bit equivalent binary representation

Octal to Binary Conversion


Each octal number converts to 3 binary digits
To convert 6538 to binary, just substitute code:

110 101 011

Example
7058 = ?2

111 000 101

7058 = 1110001012

Hexadecimal to Binary
Technique
Convert each hexadecimal digit to a 4-bit equivalent binary representation

Example
10AF16 = ?2

0001 0000 1010 1111

10AF16 = 00010000101011112

Octal to Hexadecimal
Technique
Use binary as an intermediary

Example
1F0C16 = ?8 1 F 0 C

0001

1111

0000

1100

1F0C16 = 174148

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

pp. 46-50

Fractions
Binary to decimal
10.1011 => 1 x 2-4 = 0.0625 1 x 2-3 = 0 x 2-2 = 1 x 2-1 = 0 x 20 = 1 x 21 = 0.125 0.0 0.5 0.0 2.0 2.6875

pp. 46-50

Fractions
Decimal to binary
3.14579 .14579 x 2 0.29158 x 2 0.58316 x 2 1.16632 x 2 0.33264 x 2 0.66528 x 2 1.33056 etc. p. 50

11.001001...

Binary Addition
4 Possible Binary Addition Combinations:

(1)
Carry

(3)

0 +0 00 1 +0 01

(2)
Sum

(4)

0 +1 01 1 +1 10

Note that leading zeroes are frequently dropped.

Binary Addition (1 of 2)
Two 1-bit values
A 0 0 1 1 B 0 1 0 1 A+B 0 1 1 10
two pp. 36-38

Binary Addition (2 of 2)
Two n-bit values
Add individual bits Propagate carries E.g.,
1 1

10101 + 11001 101110

21 + 25 46

Você também pode gostar