binary, decimal, & hexadecimal numbers binary numbers digital electronic circuitry using logic...

31
Binary, Decimal, & Hexadecimal Numbers Binary Numbers Digital electronic circuitry using logic gates Base-2 number system using two symbols: 0 & 1 A positional notation system with base (radix) of 2

Upload: susan-watts

Post on 23-Dec-2015

243 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary, Decimal, & Hexadecimal Numbers

• Binary Numbers Digital electronic circuitry using logic gates Base-2 number system using two symbols: 0 & 1 A positional notation system with base (radix) of 2

Page 2: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Different Number Systems

• Positional number systems The value of the number depends on the position of the digits. The value of each digit is determined by which place it appears in

the full number. Our decimal number is know as a positional number system.For example, the number 123 has a very different value than the number 321, although the same digits are used in both numbers. Is binary number system a positional number system?• NOT all number systems are positional number system. The Egyptian number system were not positional, but

rather used many additional symbols to represent larger values.

Page 3: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Different Number Systems

• Positional number systemsThe values of each position correspond to powers of the base of the number system.Our decimal number system, which uses base 10, the place values correspond to powers of 10: 1000 100 10 1 10^3 10^2 10^1 10^0

Page 4: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Number Representation System

• Representation of base 10, decimal, numbersEach digit is in 0....9, and its position determines which power of 10.

In general, we represent the whole numbers in our base 10 system in the following way:

Generalizing even further, we can represent numbers in the base, b, as follows:

Page 5: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Basic Concepts Behind the Binary• The binary system works under the exact same

principles. 10^2 | 10^1 | 10^0 2^2 | 2^1 | 2^0

• What would the binary number 1011 be in the decimal notation?

• Convert these numbers from binary to decimal.• 10• 111• 10101• 11110

Page 6: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Basic Concepts Behind the Binary• In the decimal system

H | T | O 1 | 9 | 3

(H: Hundreds column; T:Tenscolumn; O:Ones column(unit)) 10^2 | 10^1 | 10^0 1 | 9 | 3

(1*10^2)+(9*10^1)+(3*10^0)

Page 7: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Unsigned Binary Integers to Decimal• 2^4| 2^3| 2^2| 2^1| 2^0• | | | 1 | 0 (2)• | | 1 | 1 | 1 (7)• 1 | 0 | 1 | 0 | 1 (21)• 1 | 1 | 1 | 1 | 0 (30)

Page 8: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Decimal Addition 33+78

--------

Page 9: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary Addition 0 0 1 +0 +1 +0 ---- ---- ---- 0 1 1• In decimal form, 1+1=2. In binary, any digit higher than 1 puts us a

column to the left (as would 10 in decimal notation). Record the 0 in the ones column, and carry the 1 to the twos column to get an answer of "10."

• The decimal number "2" is written in binary notation as "10" (1*2^1)+(0*2^0).

1 +1 ---- 10

Page 10: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

The process is the same for multiple-bit binary numbers:

1010 +1111 ______

Step one:Column 2^0: 0+1=1.Record the 1. Temporary Result: 1; Carry: 0 Step two:Column 2^1: 1+1=10. Record the 0, carry the 1.Temporary Result: 01; Carry: 1 Step three:Column 2^2: 1+0=1 Add 1 from carry: 1+1=10. Record the 0, carry the 1.Temporary Result: 001; Carry: 1 Step four:Column 2^3: 1+1=10. Add 1 from carry: 10+1=11.Record the 11. Final result: 11001

Page 11: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

The process is the same for multiple-bit binary numbers:

1010 +1111 ______

Alternately:

11 (carry) 1010 +1111 ______ 11001

Rules of Binary Addition 0+0=0 0+1=11+0=1 1+1=10 (1+1=0, and carry 1 to the next more significant bit)

Page 12: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary AdditionTry a few examples of binary addition:

111 101 111 +110 +111 +111 ------- ------ ------

Rules of Binary Addition 0+0=0 0+1=11+0=1 1+1=10 (1+1=0, and carry 1 to the next more significant bit)

Page 13: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary Addition00011010 + 00001100 = 00100110 1 1 carries 0 0 0 1 1 0 1 0 = 26(base 10)+ 0 0 0 0 1 1 0 0 = 12(base 10)---------------------------------------- 0 0 1 0 0 1 1 0 = 38(base 10)

Rules of Binary Addition 0+0=0 0+1=11+0=1 1+1=10 (1+1=0, and carry 1 to the next more significant bit)

Page 14: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary Addition00010011 + 00111110 = 01010001 1 1 1 1 1 1 carries 0 0 0 1 0 0 1 1 = 19(base 10)+ 0 0 1 1 1 1 1 0 = 62(base 10)---------------------------------------- 0 1 0 1 0 0 0 1 = 81(base 10)

Rules of Binary Addition 0+0=0 0+1=11+0=1 1+1=10 (1+1=0, and carry 1 to the next more significant bit)

Page 15: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary AdditionNote: The rules of binary addition (without carries) are the same as the truths of the XOR gate

One and Two Input Gates

AND Gate NAND Gate

Output is TRUE only if both inputs are TRUE.

Output is FALSE only if both inputs are TRUE.

A B output

F F F

F T F

T F F

T T T

A B output

0 0 0

0 1 0

1 0 0

1 1 1

(The AND gate is useful for masking or clearing specified bit positions.)

A B output

F F T

F T T

T F T

T T F

A B output

0 0 1

0 1 1

1 0 1

1 1 0

OR Gate NOR Gate

Output is TRUE if either input (or both) is TRUE.

Output is FALSE if either input (or both) is TRUE.

A B output

F F F

F T T

T F T

T T T

A B output

0 0 0

0 1 1

1 0 1

1 1 1

(The OR gate is useful for setting specified bits.)

A B output

F F T

F T F

T F F

T T F

A B output

0 0 1

0 1 0

1 0 0

1 1 0

XOR (EXCLUSIVE OR) Gate XNOR (EXCLUSIVE NOR) Gate

(or Equality Gate)

Page 16: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary SubtractionA B A-B One digit cases 0 0 0 1 0 1 1 1 0 The One case of Borrow 10...0 1 original = 01...1andresult = 1

Page 17: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary Subtraction Unsigned 0 1 0 0 1 0 1 0 74 (base 10)- 1 0 1 0 0 20 (base 10)-------------------------- 0 (STEP THROUGH) 1 1 0 1 1 0 0--------------------------- 0 0 1 1 0 1 1 0 54(base 10)

Page 18: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary MultiplicationMultiplication in the binary system works the same way as in the decimal system:

1*1=1 1*0=0 0*1=0

101 * 11 ____ 101 101 _____ 1111

Page 19: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary DivisionFollow the same rules as in decimal division. For the sake of simplicity, throw away the remainder.For Example: 111011/11

10011 r 10 _______ 11)111011 -11 ______ 101 -11 ______ 101 11 ______ 10

Page 20: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Unsigned Decimal Integer to BinaryDivision Quotient Remainder

156 / 2 78 0

78 / 2 39 0

39 / 2 19 1

19 / 2 9 1

9 / 2 4 1

4 / 2 2 0

2 / 2 1 0

1 / 2 0 1

Decimal Binary

156 1 0 0 1 1 1 0 0

Page 21: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Hexadecimal Integers• A positional numeral system with a radix, or base, of 16• Sixteen distinct symbols, 0-9, A-F (or a-f)• Each hexadecimal digit represents four binary digits (bits).• One hexadecimal digit represents a nibble, which is half of an

octet (8 bits). • For example, byte values can range from 0 to 255 (decimal), but

may be more conveniently represented as two hexadecimal digits in the range 00 to FF. (Two hexadecimal digits together represents a byte.)

• Hexadecimal is also commonly used to represent computer memory addresses.

• A human-friendly representation of binary-coded values in computing and digital electronics.

Page 22: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary to Hexadecimal• Binary 0001.0110.1010.0111.1001.0100• Hexadecimal 16A794

Binary 0001 0110 1010 0111 1001 0100Hexadecimal 1 6 A 7 9 4

Page 23: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Hexadecimal Integers 0hex = 0dec = 0oct 0 0 0 0 1hex = 1dec = 1oct 0 0 0 1 2hex = 2dec = 2oct 0 0 1 0 3hex = 3dec = 3oct 0 0 1 1 4hex = 4dec = 4oct 0 1 0 0 5hex = 5dec = 5oct 0 1 0 1 6hex = 6dec = 6oct 0 1 1 0 7hex = 7dec = 7oct 0 1 1 1 8hex = 8dec = 10oct 1 0 0 0 9hex = 9dec = 11oct 1 0 0 1 Ahex = 10dec = 12oct 1 0 1 0 Bhex = 11dec = 13oct 1 0 1 1 Chex = 12dec = 14oct 1 1 0 0 Dhex = 13dec = 15oct 1 1 0 1 Ehex = 14dec = 16oct 1 1 1 0 Fhex = 15dec = 17oct 1 1 1 1

Page 24: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Binary Decimal Hexadecimal Binary Decimal Hexadecimal

0000 0000 0 00 0001 0000 16 10

0000 0001 1 01 0001 0001 17 11

0000 0010 2 02 0001 0010 18 12

0000 0011 3 03 0001 0011 19 13

0000 0100 4 04 0001 0100 20 14

0000 0101 5 05 0001 0101 21 15

0000 0110 6 06 0001 0110 22 16

0000 0111 7 07 0001 0111 23 17

0000 1000 8 08 0001 1000 24 18

0000 1001 9 09 0001 1001 25 19

0000 1010 10 0A 0001 1010 26 1A

0000 1011 11 0B 0001 1011 27 1B

0000 1100 12 0C 0001 1100 28 1C

0000 1101 13 0D 0001 1101 29 1D

0000 1110 14 0E 0001 1110 30 1E

0000 1111 15 0F 0001 1111 31 1F

Page 25: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Number Representation System

• Representation of base 10, decimal, numbersEach digit is in 0....9, and its position determines which power of 10.

In general, we represent the whole numbers in our base 10 system in the following way:

Generalizing even further, we can represent numbers in the base, b, as follows:

Page 26: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Hexadecimal Integers• For example, the hexadecimal number 2AF3 is equal, in decimal,

to (2 × 163) + (10 × 162) + (15 × 161) + (3 × 160), or 10995(decimal).

Page 27: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Unsigned Hexadecimal to Decimal• Multiply each digit by its corresponding power of 16:

dec = (D3 163) + (D2 162) + (D1 161) + (D0 160)

Convert the number 1128 (Hexdecimal) to Decimal

4392 = (1 x 16^3) + (1 x 16^2) + (2 x 16^1) + (8 x 16^0) Convert the number 589 (Hexdecimal) to Decimal

1417 = (1 x 16^3) + (4 x 16^2) + (1 x 16^1) + (7 x 16^0) Convert the number 1531 (Hexdecimal) to Decimal

5425 = (1 x 16^3) + (5 x 16^2) + (3 x 16^1) + (1 x 16^0) Convert the number FA8 (Hexdecimal) to Decimal

4008 = (0 x 16^3) + (F x 16^2) + (A x 16^1) + (8 x 16^0)

Page 28: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Power of 16 in DecimalPower of 16 Decimal Value

16^0 1

16^1 16

16^2 256

16^3 4,096

16^4 65,536

16^5 1,048,576

16^6 16,777,216

16^7 268,435,456

Page 29: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Unsigned Decimal Integer to HexadecimalDivision Quotient Remainder

1128 / 16 70 8 70 / 16 4 6 4 / 16 0 4

Decimal Hexadecimal1128 468

Page 30: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Two’s Complement

1. As an action: (Assume the starting value is 1011)1. Flip the bits from the starting value.1011 => 01002. Add one to get the answer.0100 + 1 => 0101

Page 31: Binary, Decimal, & Hexadecimal Numbers Binary Numbers  Digital electronic circuitry using logic gates  Base-2 number system using two symbols: 0 & 1

Signed IntegerMSB indicates sign: 0 is positive; 1is negative

1XXX XXXX0XXX XXXX

Two’s-ComplementA – B = A + ( -B )1 – 1 = 1 + ( -1 )

Starting Value 0000 0001 (+1 in decimal)

Step 1: Reverse the bits 1111 1110

Step 2: Add 1 to the value from step 1 +0000 0001

Sum:Two’s-complement representation 1111 1111 (-1 in decimal)

1 0000 0001

-1 1111 1111

1 + ( -1 ) (1)0000 0000