Binary - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Binary

Description:

How does a computer 'remember' pictures? Documents? Smells? Binary versus Decimal. Binary representation uses just digits 0, 1. Consider a binary odometer on a car ... – PowerPoint PPT presentation

Number of Views:159
Avg rating:3.0/5.0
Slides: 32
Provided by: jacob78
Category:
Tags: binary

less

Transcript and Presenter's Notes

Title: Binary


1
Binary
  • What is really in the mind of a computer?
  • Binary, bits (binary digits)
  • Everything is encoded in binary
  • How does a computer remember pictures?
  • Documents? Smells?

2
Binary versus Decimal
  • Binary representation uses just digits 0, 1
  • Consider a binary odometer on a car
  • Converting binary to decimal and vice versa
  • What is 23 in binary?
  • What is 101010 in decimal?
  • Think in powers of two
  • KB1024 bytes? the debate continues

3
Grouping Binary Digits
  • Groups of bits represent data, instructions
  • Numbers typically stored as 32 bits
  • ASCII
  • standard encoding of characters
  • all characters encoded as eight bits
  • example a is the number 01000001
  • Unicode created to address large character sets
  • Unicode uses 16 bits

4
Bits and Switches
  • A bit has two possible values one or zero
  • The bit is a logical entity a number
  • A bit has a corresponding physical entity
  • In computers, this is an electrical switch
  • Consider a light switch
  • Each electrical switch has two states
  • it is set to pass current (like a 1 for a bit)
  • it is set to not pass current (like a 0 for a
    bit)

5
Switches to Gates
  • Combine switches in logical ways via gates
  • Types AND, OR, NOT, etc.
  • AND is 1 when both inputs are 1
  • OR is 1 when either inputs are 1
  • NOT is opposite of single input
  • Each type has a corresponding graphical symbol

6
Gates
7
One More Gate XOR
  • XOR (exclusive or) gate
  • Results in 0 when inputs are same
  • Results in 1 when inputs are different
  • Useful in complementing an input bit

8
Gates to Circuits
  • A circuit board designed using many gates
  • Circuits often depicted graphically using gate
    symbols
  • Example the one-bit adder circuit
  • Consider adding two one-bit numbers A, B
  • The result is a two-bit number C S where S is
    the sum of the bits and C is the carry bit

9
One Bit Adder
A
OR
S
AND
NOT
B
C
AND
10
Circuits to Larger Circuits
  • Begin with circuit design
  • Then establish means to manufacture it
  • Another circuit designer then uses it as a part
  • Smaller designs used to make medium designs
  • Medium designs used to make larger designs
  • Chips and circuit boards are nothing more than
    very large designs in very small packages

11
Boolean Logic
  • Boolean logic is a branch of mathematics
  • A Boolean variable has only one of two values
  • true (corresponding to a 1 for a bit)
  • false (corresponding to a 0 for a bit)
  • Three-way correspondence among binary digits,
    electrical switches, Boolean variables
  • Gives a mathematical model of computation
  • Revisit the half-adder with this in mind

12
Boolean Expression for Adder
A
OR
S
AND
NOT
B
C
AND
S (A or B) and (not C) C A and B
13
Majority Function
  • Returns 1 when two of three inputs are 1
  • Boolean expression
  • M ABC ABC ABC ABC
  • Ways to represent this function
  • boolean expression
  • circuit diagram
  • truth table

14
Circuit Truth Table
15
Translation Practice
  • Translate to a circuit diagram1) F A B2) F
    A B C3) F AB AC4) F AB AB5) F
    ABC A6) F (AB) C7) F (AB C)

16
Important Number Systems
  • We use decimal system, base 10
  • Computers use binary system, base 2
  • Sometimes computer science uses
  • octal system, base 8
  • hexadecimal system, base 16
  • Trick for hexadecimal is using letters A through
    F for the digits 10 through 15

17
Examples of Octal, Hexadecimal
18
Conversion Practice
  • Convert to hex 1111 1010 0010 0001
  • Convert to octal 7EDC81A0
  • Convert to hex, octal 0011 0000 1110 1101
  • Convert to decimal 1010.1001
  • Convert to binary 27.25

19
Data Types
  • Need a plan to represent the basic types
  • whole s, strings, booleans, real s
  • How much space for each?
  • How to represent each?
  • Floating point is especially tricky
  • IEEE 754 standardized three formats
  • single (32 bits), double (64), extended (80)

20
Real Numbers as 10YY
21
IEEE Single, Double Formats
22
IEEE Single Precision
  • Bits split into sign bit, exponent, fraction
  • Value (-1)(sign bit) x fraction-1 x 2(exp
    127)
  • Consider 0.01 1 x 2(-2)
  • sign bit 0, fraction 1-1, exp -2127
  • Can also represent special numbers
  • infinity 1s in exponent field 0s in fraction
  • NaN (Not a Number) for illegal results

23
Converting to IEEE Format
  • Convert this 0.1
  • Normalize 1.0 x 2-1
  • Convert exponent1.0 x 2-1 127 1.0 x 2126
  • Fill in the three parts (sign, exp,
    fraction)sign 0exponent 01111110fraction
    00000000000000000000000

24
Binary Digits and Real Numbers
  • 1/2 0.5
  • 1/4 0.25
  • 1/8 0.125
  • 1/16 0.0625
  • 1/32 0.03125
  • 1/64 0.015625
  • 1/128 0.0078125
  • 1/256 0.00390625
  • 1/512 0.001953125

25
Floating Point Practice
  • Put these numbers in binary form
  • Then in IEEE Single Precision format
  • 0.5
  • 1
  • 1.5
  • 0.01
  • 7.1

26
Binary Arithmetic
  • How do we add binary numbers?
  • Same as decimal allow for a carry digit
  • For subtraction, need concept of negative
  • What is a negative binary number?
  • Use high-order bit to indicate sign
  • How to convert a number to its negative?
  • Use twos complement

27
Twos Complement
  • Basic method is flip bits and add one, e.g.
  • flip bits of 0011 (decimal 3) and get 1100
  • then add one giving 1101 (-3 in 2s comp)
  • Without 2s complement, a 4-bit number (0000 thru
    1111) can represent 0 thru 15
  • With 2s complement, a 4-bit number can represent
    -8 (as 1000) thru 7 (as 0111)
  • Converting negative decimal to binary

28
Twos Complement
  • 0000 0
  • 0001 1
  • 0010 2
  • 0011 3
  • 0100 4
  • 0101 5
  • 0110 6
  • 0111 7

1000 -8 1001 -7 1010 -6 1011 -5 1100
-4 1101 -3 1110 -2 1111 -1
29
Converting to 2s Complement
  • Consider -3 in decimal
  • Convert to binary
  • Get 3 in binary 0011
  • Flip the bits 1100
  • Add one 1100 1 1101
  • -3 in decimal 1101 in binary

30
Subtracting with 2s Complement
  • Consider 9 - 3 00001001 - 00000011
  • Convert number to subtract using 2s complement
    -00000011 11111101
  • Then add the result to the first number
    0000100111111101-------------- 100000110
  • Throw away the carry out from the sign bit
  • Final answer 00000110 6

31
Overflow
  • What about a 4-bit addition 0001 0111?
  • Result is 1000, but 1 7 -8? I dont think so!
  • And so begins the need for overflow handling
  • Overflow is always detectable, but not always
    handled left to software to decide
  • Detected when carry into sign bit not same as
    carry out of sign bit
Write a Comment
User Comments (0)
About PowerShow.com