Your browser **doesn't support the features required** by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest **Chrome**, **Safari** or **Firefox** browser.

**CIS 115**

Lecture 8: Encoding Data

**George Boole**

Image Source: Wikipedia

**Gottfried Willhelm von Leibniz**

Image Source: Wikipedia

**Charles Babbage**

Image Source: Wikipedia

**Claude Shannon**

Image Source: Wikipedia

**George Stibitz**

Image Source: Wikipedia

**Complex Numerical Calculator**

Image Source: Computer History Museum

**Binary - Natural Numbers**

128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |

0*128 | 0*64 | 1*32 | 0*16 | 1*8 | 0*4 | 1*2 | 0*1 |

32 + 8 + 2 = 42

**Binary Data Types**

- Unsigned Integer (Natural Number)
- Signed Integer
- Float

**Negative Numbers**

- One's Compliment - Just invert the bits
- Sign Bit: 0 is positive, 1 is negative

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

**Negative Numbers**

- One's Compliment - Just invert the bits
- Sign Bit: 0 is positive, 1 is negative

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | -42 |

**One's Compliment Addition**

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

+

1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | -42 |

=

**One's Compliment Addition**

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

+

1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | -42 |

=

1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | -0 |

Hmm, that's not quite right...

**Negative Numbers**

- Two's Compliment -

Invert the bits and add 1

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

invert

1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |

**Negative Numbers**

- Two's Compliment -

Invert the bits and add 1

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

invert

1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |

plus 1

1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | -42 |

**Two's Compliment Addition**

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

+

1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | -42 |

=

**Two's Compliment Addition**

0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 |

+

1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | -42 |

=

0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |

That works!

**Other Values**

Binary | Unsigned | Signed |

00000000 | 0 | 0 |

00000001 | 1 | 1 |

00000010 | 2 | 2 |

01111110 | 126 | 126 |

01111111 | 127 | 127 |

10000000 | 128 | -128 |

10000001 | 129 | -127 |

10000010 | 130 | -126 |

11111110 | 254 | -2 |

11111111 | 255 | -1 |

**Integer Overflow**

Image Source: Randall Munroe (XKCD)

**Range of Values**

- 8 Bit numbers
- Unsigned: 0 → 2
^{8}- 1 - Signed: -(2
^{7}) → 2^{7}- 1

- Unsigned: 0 → 2
- General Numbers - n bits
- Unsigned: 0 → 2
^{n}- 1 - Signed: -(2
^{n-1}) → 2^{n-1}- 1

- Unsigned: 0 → 2

**Rational Numbers**

The decimal point can "float" around

**Floating Point**

- IEEE 754 Standard - 16 bits (Half)
- The exponent has a bias of 15
- The leading one of the mantissa is implied

- | Exponent | Mantissa | |||||||||||||

0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |

**Floating Point Example**

- | Exponent | Mantissa | |||||||||||||

0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |

Mantissa: (1).01010 = 1.3125

Exponent: 10100 - 01111 = 20 - 15 = 5

**Floating Point Example**

- | Exponent | Mantissa | |||||||||||||

0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |

Mantissa: (1).01010 = 1.3125

Exponent: 10100 - 01111 = 20 - 15 = 5

Value: 1.3125 * 2^{5} = 42

1.01010 * 2^{5} = 101010 = 42

**Range of Values**

- -65504 → +65504
- 5.96046 x 10
^{-8}: minimum positive - 0 11111 0000000000 = infinity
- 1 11111 0000000000 = -infinity
- 0 01101 0101010101 ≈ 0.33325 ≈ 1/3

Not exact, but not bad either

**Real World**

- Integer - 32 bits
- Long Integer - 64 bits
- Half - 16 bits (5 + 10)
- Float (Single) - 32 bits (8 + 23)
- Double - 64 bits (11 + 52)

**Text - ASCII**

Image Source: ASCIItable.com

**Text - ASCII**

011001100110111101110010011101000111

100100100000011101000111011101101111

**Text - ASCII**

011001100110111101110010011101000111

100100100000011101000111011101101111

- 01100110 (102)
- 01101111 (111)
- 01110010 (114)
- 01110100 (116)
- 01111001 (121)
- I00100000 (32)
- 01110100 (116)
- 01110111 (119)
- 01101111 (111)

**Text - ASCII**

011001100110111101110010011101000111

100100100000011101000111011101101111

- 01100110 (102) - f
- 01101111 (111) - o
- 01110010 (114) - r
- 01110100 (116) - t
- 01111001 (121) - y
- I00100000 (32) - sp
- 01110100 (116) - t
- 01110111 (119) - w
- 01101111 (111) - o

**Images**

Image Source: Wikipedia

**RGB Colors**

Image Source: Wikipedia

**Compression**

How much wood could

a woodchuck chuck if a

woodchuck could chuck wood?

**Compression**

How much wood could

a woodchuck chuck if a

woodchuck could chuck wood?

wood = 1 could = 2 chuck = 3

**Compression**

How much wood could

a woodchuck chuck if a

woodchuck could chuck wood?

wood = 1 could = 2 chuck = 3

How much 1 2 a 13 3 if a 13 2 3 1?

**Image Compression**

Image Source: D. Kriesel

Assignments

- Read and be prepared to discuss:
*Pattern on the Stone*Chapter 7: Speed: Parallel Computers

- Blog 4: Computer Systems in Daily Life - Due 2/24 10:00 PM
- Scratch Sorting Project - Due 2/19 10:00 PM

**Blog 4: Computer Systems in Daily Life**

We interact with a variety of computer systems on a daily basis, but most of the time we don’t take the time to think about where they came from and how they work. Choose a computer system you see in your everyday life and write about it and its history. Tell us how it works and how it affects us in our daily life. A simple example would be the keycard entry systems at the K-State dorms and the engineering labs. Some questions to ask yourself while you are doing your research:

- Who created this system?
- What are the underlying technologies?
- Is this a very common system, or something unique to a particular field or use?
- How long has this system been around?
- How difficult would life be without this system?
- Are there any privacy, security or safety concerns with this system? Are there any concerns if this system didn’t exist?

**Binary Worksheet**