Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 101 Binary Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions.

Similar presentations


Presentation on theme: "Computer Science 101 Binary Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions."— Presentation transcript:

1 Computer Science 101 Binary Systems

2 Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions (23.27) Decimal Fractions (23.27) Letters for text Letters for text

3 Computers Binary Numbers (base 2) Binary Numbers (base 2) Two’s complement and sign-magnitude Two’s complement and sign-magnitude Binary fractions and floating point Binary fractions and floating point ASCII codes for characters (A  65) ASCII codes for characters (A  65)

4 Why binary? Information is stored in computer via voltage levels. Information is stored in computer via voltage levels. Using decimal would require 10 distinct and reliable levels for each digit. Using decimal would require 10 distinct and reliable levels for each digit. This is not feasible with reasonable reliability and financial constraints. This is not feasible with reasonable reliability and financial constraints. Everything in computer is stored using binary: numbers, text, programs, pictures, sounds, videos,... Everything in computer is stored using binary: numbers, text, programs, pictures, sounds, videos,...

5 How can that be? Everything in computer is stored using binary: numbers, text, programs, pictures, sounds, videos,... Everything in computer is stored using binary: numbers, text, programs, pictures, sounds, videos,...

6 Transistor A transistor is an electronic switch A transistor is an electronic switch Basic unit of modern computer storage Basic unit of modern computer storage Two steady states based on voltage levels Two steady states based on voltage levels Say, 500 million transistors on a chip 1 cm 2 Say, 500 million transistors on a chip 1 cm 2 Change states in billionth of sec Change states in billionth of sec Solid state Solid state

7 Morse Code Morse Code

8 Morse Code Tree

9 Decimal: Non-negatives Base 10 Base 10 Uses decimal digits: 0,1,2,3,4,5,6,7,8,9 Uses decimal digits: 0,1,2,3,4,5,6,7,8,9 Positional System - position gives power of the base Positional System - position gives power of the base Example: 3845 = 3x10 3 + 8x10 2 + 4x10 1 + 5x10 0 Example: 3845 = 3x10 3 + 8x10 2 + 4x10 1 + 5x10 0 Positions: …543210 Positions: …543210

10 Binary: Non-negatives Base 2 Base 2 Uses binary digits (bits): 0,1 Uses binary digits (bits): 0,1 Positional system Positional system Example: 1101 = 1x2 3 + 1x2 2 + 0x2 1 + 1x2 0 Example: 1101 = 1x2 3 + 1x2 2 + 0x2 1 + 1x2 0

11 Conversions ExternalInternal (Human) (Computer) 25 11001 A01000001 ExternalInternal (Human) (Computer) 25 11001 A01000001 Humans want to see and enter numbers in decimal. Humans want to see and enter numbers in decimal. Computers must store and compute with bits. Computers must store and compute with bits.

12 Binary to Decimal Conversion Algorithm: Algorithm: Expand binary number using positional scheme.Expand binary number using positional scheme. Perform computation using decimal arithmetic.Perform computation using decimal arithmetic. Example: 11001 2  1x2 4 + 1x2 3 + 0x2 2 + 0x2 1 + 1x2 0 = 2 4 + 2 3 + 2 0 = 16 + 8 + 1 = 25 10 Example: 11001 2  1x2 4 + 1x2 3 + 0x2 2 + 0x2 1 + 1x2 0 = 2 4 + 2 3 + 2 0 = 16 + 8 + 1 = 25 10

13 Decimal to Binary - Algorithm 1 Algorithm: While N  0 do Set N to N/2 (whole part) Record the remainder (1 or 0) end-of-loop Set A to remainders in reverse order Algorithm: While N  0 do Set N to N/2 (whole part) Record the remainder (1 or 0) end-of-loop Set A to remainders in reverse order

14 Decimal to binary - Example Example: Convert 324 10 to binary N Rem N Rem 324 1620 5 0 810 2 1 401 1 0 200 0 1 100 Example: Convert 324 10 to binary N Rem N Rem 324 1620 5 0 810 2 1 401 1 0 200 0 1 100 324 10 = 101000100 2 324 10 = 101000100 2

15 Decimal to Binary - Algorithm 2 Algorithm: Set A to 0 (all bits 0) While N  0 do Find largest P with 2 P  N Set bit in position P of A to 1 Set N to N - 2 P end-of-loop Algorithm: Set A to 0 (all bits 0) While N  0 do Find largest P with 2 P  N Set bit in position P of A to 1 Set N to N - 2 P end-of-loop

16 Decimal to binary - Example Example: Convert 324 10 to binary N Power P A 324 256 8 100000000 68 64 6 101000000 4 4 2 101000100 0 Example: Convert 324 10 to binary N Power P A 324 256 8 100000000 68 64 6 101000000 4 4 2 101000100 0 324 10 = 101000100 2 324 10 = 101000100 2

17 Binary Addition One bit numbers: + 0 1 0 | 0 1 1 | 1 10 One bit numbers: + 0 1 0 | 0 1 1 | 1 10 Example 1111 1 110101 (53) + 101101 (45) 1100010 (98) Example 1111 1 110101 (53) + 101101 (45) 1100010 (98)

18 Octal Numbers Base 8 Digits 0,1,2,3,4,5,6,7 Base 8 Digits 0,1,2,3,4,5,6,7 Number does not have so many digits as binary Number does not have so many digits as binary Easy to convert to and from binary Easy to convert to and from binary Often used by people who need to see the internal representation of data, programs, etc. Often used by people who need to see the internal representation of data, programs, etc.

19 Octal Conversions Octal to Binary Octal to Binary Simply convert each octal digit to a three bit binary number. Simply convert each octal digit to a three bit binary number. Example: 536 8 = 101 011 110 2 Example: 536 8 = 101 011 110 2 Binary to Octal Binary to Octal Starting at right, group into 3 bit sections Starting at right, group into 3 bit sections Convert each group to an octal digit Convert each group to an octal digit Example 11011111101010 2 = 011 011 111 101 010 = 33752 8 Example 11011111101010 2 = 011 011 111 101 010 = 33752 8

20 Hexadecimal Base 16 Digits 0,…,9,A,B,C,D,E,F Base 16 Digits 0,…,9,A,B,C,D,E,F Hexadecimal  Binary Hexadecimal  Binary Just like Octal, only use 4 bits per digit. Just like Octal, only use 4 bits per digit. Example: 98C3 16 = 1001 1000 1100 0011 2 Example: 98C3 16 = 1001 1000 1100 0011 2 Example 11010011101011 2 = 0011 0100 1110 1011 = 34EB Example 11010011101011 2 = 0011 0100 1110 1011 = 34EB

21 Python example

22


Download ppt "Computer Science 101 Binary Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions."

Similar presentations


Ads by Google