Download presentation

Presentation is loading. Please wait.

Published byAshton McWilliams Modified over 3 years ago

1
Binary Numbers 1

2
The Decimal Number System (cont) 2 The decimal number system is also known as base 10. The values of the positions are calculated by taking 10 to some power. Why is the base 10 for decimal numbers? o Because we use 10 digits, the digits 0 through 9.

3
The Decimal Number System - base 10 3 The decimal number system is a positional number system with a base 10. Example: 1011 1011 2 = 1000 + 000 + 10 + 1 = 1 x 2 3 + 0 x2 2 + 1 x 2 1 + 1 x 2 0 = 11 10 1000 000101 1 x 2 3 0x2 2 1 x 2 1 1x 2 0

4
The Binary Number System 4 The binary number system is also known as base 2. The values of the positions are calculated by taking 2 to some power. Why is the base 2 for binary numbers? o Because we use 2 digits, the digits 0 and 1.

5
The Binary Number System – base 2 5 The decimal number system is a positional number system with a base 10. Example: 5623 5623 = 5000 + 600 + 20 + 3 = 5 x 10 3 + 6 x10 2 + 2 x 10 1 + 3 x 10 0 5000 600203 5 x 10 3 6 x10 2 2 x 10 1 3 x 10 0

6
Why Bits (Binary Digits)? Computers are built using digital circuits – Inputs and outputs can have only two values – True (high voltage) or false (low voltage) – Represented as 1 and 0 Can represent many kinds of information – Boolean (true or false) – Numbers (23, 79, …) – Characters (a, z, …) – Pixels – Sound Can manipulate in many ways – Read and write – Logical operations – Arithmetic – … 6

7
Base 10 and Base 2 Base 10 – Each digit represents a power of 10 – 54173 10 = 5 x 10 4 + 4 x 10 3 + 1 x 10 2 + 7 x 10 1 + 3 x 10 0 Base 2 – Each bit represents a power of 2 – 10101 2 = 1 x 2 4 + 0 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0 = 21 10 7

8
The Binary Number System (cont) 8 The binary number system is also a positional numbering system. Instead of using ten digits, 0 - 9, the binary system uses only two digits, 0 and 1. Example of a binary number and the values of the positions: 1 0 0 1 1 0 1 2 6 2 5 2 4 2 3 2 2 2 1 2 0

9
Converting from Binary to Decimal 9 1 0 0 1 1 0 1 1 X 2 0 = 1 2 6 2 5 2 4 2 3 2 2 2 1 2 0 0 X 2 1 = 0 1 X 2 2 = 4 2 0 = 1 1 X 2 3 = 8 2 1 = 2 0 X 2 4 = 0 2 2 = 4 0 X 2 5 = 0 2 3 = 8 1 X 2 6 = 64 2 4 = 16 77 10 2 5 = 32 2 6 = 64

10
Converting from Binary to Decimal (cont) Practice conversions: Binary Decimal 11101 1010101 100111 10

11
Converting From Decimal to Binary (cont) 11 Make a list of the binary place values up to the number being converted. Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions from right to left. Continue until the quotient is zero. Example:42 10 2 5 2 4 2 3 2 2 2 1 2 0 32 16 8 4 2 1 1 0 1 0 1 0 42/2 = 21 and R = 0 21/2 = 10 and R = 1 10/2 = 5 and R = 0 5/2 = 2 and R = 1 2/2 = 1 and R = 0 1/2 = 0 and R = 1 42 10 = 101010 2

12
Example 12 10 We repeatedly divide the decimal number by 2 and keep remainders – 12/2 = 6 and R = 0 – 6/2 = 3and R = 0 – 3/2 = 1and R = 1 – 1/2 = 0and R = 1 The binary number representing 12 is 1100

13
Converting From Decimal to Binary (cont) Practice conversions: Decimal Binary 59 82 175 13

14
Exercises Find the binary the decimal number represented by the following binary sequences: – 110101 – 10111010 Represent the number 135 in base 2.

15
15 Fractional Numbers Examples:456.78 10 = 4 x 10 2 + 5 x 10 1 + 6 x 10 0 + 7 x 10 -1 +8 x 10 -2 1011.11 2 = 1 x 2 3 + 0 x 2 2 + 1 x 2 1 + 1 x 2 0 + 1 x 2 -1 + 1 x 2 -2 = 8 + 0 + 2 + 1 + 1/2 + ¼ = 11 + 0.5 + 0.25 = 11.75 10 Conversion from binary number system to decimal system Examples: 111.11 2 = 1 x 2 2 + 1 x 2 1 + 1 x 2 0 + 1 x 2 -1 + 1 x 2 -2 = 4 + 2 + 1 + 1/2 + ¼ = 7.75 10 Examples: 11.011 2 2 2 2 1 2 0 2 -1 2 -2 2 - 3 4 2 1 ½ ¼ 1/8 2 1 0 -1 -2 -3 xxxx

16
16 Fractional numbers Examples: 7.75 10 = (?) 2 1.Conversion of the integer part: same as before – repeated division by 2 7 / 2 = 3 (Q), 1 (R) 3 / 2 = 1 (Q), 1 (R) 1 / 2 = 0 (Q), 1 (R) 7 10 = 111 2 2.Conversion of the fractional part: perform a repeated multiplication by 2 and extract the integer part of the result 0.75 x 2 =1.50 extract 1 0.5 x 2 = 1.0 extract 1 0.75 10 = 0.11 2 0.0 stop Combine the results from integer and fractional part, 7.75 10 = 111.11 2 How about choose some of Examples: try 5.625 write in the same order 421 1/21/41/8 =0.5 =0.25=0.125

17
17 Fractional Numbers (cont.) Solution : (0.625) 10 = (0.101) 2 Exercise 2: Convert (0.6) 10 to its binary form Exercise 1: Convert (0.625)10 to its binary form Solution: 0.625 x 2 = 1.25 extract 1 0.25 x 2 = 0.5 extract 0 0.5 x 2 = 1.0 extract 1 0.0 stop 0.6 x 2 = 1.2 extract 1 0.2 x 2 = 0.4 extract 0 0.4 x 2 = 0.8 extract 0 0.8 x 2 = 1.6 extract 1 0.6 x 2 = (0.6) 10 = (0.1001 1001 1001 …) 2

18
18 Fractional Numbers (cont.) Exercise 3: Convert (0.8125) 10 to its binary form Solution: 0.8125 x 2 = 1.625 extract 1 0.625 x 2 = 1.25 extract 1 0.25 x 2 = 0.5 extract 0 0.5 x 2 = 1.0 extract 1 0.0 stop (0.8125) 10 = (0.1101) 2

19
19 Fractional Numbers (cont.) Errors – One source of error in the computations is due to back and forth conversions between decimal and binary formats Example: (0.6) 10 + (0.6) 10 = 1.2 10 Since (0.6) 10 = (0.1001 1001 1001 …) 2 Lets assume a 8-bit representation: (0.6) 10 = (0.1001 1001) 2, therefore 0.60.10011001 + 0.6 +0.10011001 1.00110010 Lets reconvert to decimal system: (1.00110010) b = 1 x 2 0 + 0 x 2 -1 + 0 x 2 -2 + 1 x 2 -3 + 1 x 2 -4 + 0 x 2 -5 + 0 x 2 -6 + 1 x 2 -7 + 0 x 2 -8 = 1 + 1/8 + 1/16 + 1/128 = 1.1953125 Error = 1.2 – 1.1953125 = 0.0046875

20
Bits, Bytes, and Words A bit is a single binary digit (a 1 or 0). A byte is 8 bits A word is 32 bits or 4 bytes Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits Programming languages use these standard number of bits when organizing data storage and access. 20

21
Adding Two Integers: Base 10 From right to left, we add each pair of digits We write the sum, and add the carry to the next column 21 198 +264 Sum Carry 011 +001 Sum Carry 2121 6161 4040 0101 0101 1010

22
Example 10011110 1101111 + 111 1101 -------------------- ------------------- = 101 0 0 101 = 1111100

23
23 Fractional Numbers (cont.) Errors – One source of error in the computations is due to back and forth conversions between decimal and binary formats Example: (0.6) 10 + (0.6) 10 = 1.2 10 Since (0.6) 10 = (0.1001 1001 1001 …) 2 Lets assume a 8-bit representation: (0.6) 10 = (0.1001 1001) 2, therefore 0.60.10011001 + 0.6 +0.10011001 1.00110010 Lets reconvert to decimal system: (1.00110010) b = 1 x 2 0 + 0 x 2 -1 + 0 x 2 -2 + 1 x 2 -3 + 1 x 2 -4 + 0 x 2 -5 + 0 x 2 -6 + 1 x 2 -7 + 0 x 2 -8 = 1 + 1/8 + 1/16 + 1/128 = 1.1953125 Error = 1.2 – 1.1953125 = 0.0046875

24
Binary subtraction

25
Binary subtraction (Cont)

27
Exercise 10010101 - 11011 =? 10000001 - 111 = ?

28
Spring 2007, Jan. 17ELEC 2200 (Agrawal)28 Binary Multiplication 1 0 0 0 two = 8 ten multiplicand 1 0 0 1 two = 9 ten multiplier ____________ 1 0 0 0 0 0 0 0partial products 0 0 0 0 1 0 0 0 ____________ 1 0 0 1 0 0 0 two = 72 ten

29
Spring 2007, Jan. 17ELEC 2200 (Agrawal)29 Binary Division 1 3 Quotient 1 1 / 1 4 7Divisor / Dividend 1 1 3 7 Partial remainder 3 3 4 Remainder 0 0 0 0 1 1 0 1 1 0 1 1 / 1 0 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 0

30
30 Bitwise Operators: Shift Left/Right Shift left (<<): Multiply by powers of 2 – Shift some # of bits to the left, filling the blanks with 0 Shift right (>>): Divide by powers of 2 – Shift some # of bits to the right For unsigned integer, fill in blanks with 0 What about signed integers? Varies across machines… – Can vary from one machine to another! 0011010053 1101000053<<2 0011010053 0000110153>>2

31
Boolean Algebra to Logic Gates Logic circuits are built from components called logic gates. The logic gates correspond to Boolean operations +, *,. Binary operations have two inputs, unary has one OR + AND * NOT

32
AND A B Logic Gate: ABA*B 000 010 100 111 Truth Table: A*B

33
A B Logic Gate: ABA+B 000 011 101 111 Truth Table: A+B OR

34
NOT ALogic Gate: (also called an inverter) aA 01 10 Truth Table: A or A

35
n -input Gates Because + and * are binary operations, they can be cascaded together to OR or AND multiple inputs. A B C A B C A+B+C A B A B C ABC

36
NAND and NOR Gates NAND and NOR gates can greatly simplify circuit diagrams. As we will see, can you use these gates wherever you could use AND, OR, and NOT. NAND NORAB A B 001 011 101 110 AB 001 010 100 110

37
XOR and XNOR Gates XOR is used to choose between two mutually exclusive inputs. Unlike OR, XOR is true only when one input or the other is true, not both. XOR XNOR AB A B 000 011 101 110 AB 001 010 100 111

38
Binary Sums and Carries abSumabCarry 000000 011010 101100 110111 38 XORAND 0100 0101 + 0110 0111 1010 1100 69 103 172

39
Spring 2007, Jan. 17ELEC 2200 (Agrawal)39 Design Hardware Bit by Bit Adding two bits: abhalf_sumcarry_out 0000 0110 1010 1101 Half-adder circuit a b half_sum carry_out XOR AND

40
Half Adder (1-bit) ABS(um)C(arry) 0000 0110 1010 1101 Half Adder AB S C

41
Half Adder (1-bit) ABS(um)C(arry) 0000 0110 1010 1101 A B Sum Carry

42
Full Adder CinABS(um)Cout 00000 00110 01010 01101 10010 10101 11001 11111 Full Adder AB S Cout Carry In (Cin)

43
Full Adder A B Cin Cout S H.A.

44
Full Adder Cout S Half Adder S C A B Half Adder S C A B B A Cin

45
4-bit Ripple Adder using Full Adder Full Adder AB Cin Cout S S0 A0B0 Full Adder AB Cin Cout S S1 A1B1 Full Adder AB Cin Cout S S2 A2B2 Full Adder AB Cin Cout S S3 A3B3 Carry A B S C Half Adder A B Cin Cout S H.A. Full Adder

46
Working with Large Numbers 46 0 1 0 1 0 0 0 0 1 0 1 0 0 1 1 1 = ? Humans cant work well with binary numbers; there are too many digits to deal with. Memory addresses and other data can be quite large. Therefore, we sometimes use the hexadecimal number system.

47
The Hexadecimal Number System The hexadecimal number system is also known as base 16. The values of the positions are calculated by taking 16 to some power. Why is the base 16 for hexadecimal numbers ? – Because we use 16 symbols, the digits 0 and 1 and the letters A through F. 47

48
The Hexadecimal Number System (cont) Binary Decimal Hexadecimal 0 0 0 1010 10 A 1 1 1 1011 11 B 10 2 2 1100 12 C 11 3 3 1101 13 D 100 4 4 1110 14 E 101 5 5 1111 15 F 110 6 6 111 7 7 1000 8 8 1001 9 9 48

49
The Hexadecimal Number System (cont) Example of a hexadecimal number and the values of the positions: 3 C 8 B 0 5 1 16 6 16 5 16 4 16 3 16 2 16 1 16 0 49

50
Example of Equivalent Numbers 50 Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 1 2 Decimal: 20647 10 Hexadecimal: 50A7 16 Notice how the number of digits gets smaller as the base increases.

51
Summary Convert binary to decimal Decimal to binary Binary operation Logic gates Use of logic gates to perform binary operations – Half adder – Full adder The need of Hexadecimal Hexadecimal

52
Next lecture (Data representation) Put this all together – negative and position integer representation – unsigned – Signed – Excess – Tows complement Floating point representation – Single and double precision Character, colour and sound representation

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google