Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSIS-110 Introduction to Computer Science

Similar presentations


Presentation on theme: "CSIS-110 Introduction to Computer Science"— Presentation transcript:

1 CSIS-110 Introduction to Computer Science
Dr. Meg Fryling “Dr. Meg” Fall 2012 @SienaDrMeg #csis110

2 Lecture Six Agenda Questions? Assignments
HW 1 - Part III Gotchas and Example WinSCP CSI Chapter 4 – Data Representation CSI Chapter 5 - Gates and Circuits

3 Assignments Readings: See course scheduled on syllabus Homework 1
The textbook readings are going to help you with homeworks AND labs Homework 1 Due this Weds 9/26/12 by the START of class Save your program and your picture to your hw1 folder on Z-Drive Also, print program and attach to Part I Make sure you show your work in Part I Lab 2 Due at START of lab 3 Coming to lab late does NOT extend your due date

4 Homework 1 Part III – collage.py
What you need to do: Create 2 new functions, to be called in the createCollage function Update code to accommodate your picture size canvas = makeEmptyPicture (400, 936) copy (orig, canvas, 200, 0) Add calls to your two new functions in the createCollage function Add calls to the copy function after each of the calls to your new functions Assignment 1 – Part III Review You can work on this assignment on your local PC/laptop but be sure to have the program and your picture copied (e.g. WinSCP) to your Z Drive hw1 folder by start of class on due date The sample program has done much of the work for you including makeEmptyPicture() call Creates collage with original pic and negative image of pic by copying each picture pixel by pixel to the canvas. Using loops to select each pixel in the source and move it to the target (canvas). Selects the first x coordinate (0), then each y value (0 to ?) for that x value. Then it moves on to the next x coordinate (1) and selects each y value (0 to ?) for that x value, etc. Horizontal mirror function is already done! What you need to do: Create 2 additional functions, to be called in the createCollage function that modify original pic in different ways (your Python text will be extremely helpful). All four pictures should look different. You will need to make a change to this line of code based on the picture you select: makeEmptyPicture (400, 936) You will need to make a change to this line of code based on the picture you select: copy (orig, canvas, 200, 0) You will need to add calls to your two new functions in the createCollage function You will need to add calls to the copy function after each of the calls to your new functions Other: setMediaPath() - Navigate to the location of the bigben.jpg file. This can be retrieved from csis110.common and saved to your local computer/laptop so you can work on your program remotely. Make sure your program AND YOUR picture are in the hw1 folder on your Z Drive by the due date/time. Comments start with # When you try original program with another picture it doesn’t work. What does that tell you? Add SMALL change then save load to see if you get any syntax errors. The cursor is not always on the line of code that is actually the problem. Look above it. Can comment out code that is causing a problem. It will be skipped. Then add back SLOWLY.

5 Gotcha

6 Gotcha

7 Comment out lines of code to isolate the problem:
#grayScale (orig) #copy (orig, canvas, 400, 0)

8 WinSCP Note: You may get a security message the first time you login. Just click ‘yes’ or ‘OK’

9 WinSCP

10 Worksheet Question 1 (refresher) Show your work
Put your names on the worksheet and hand-in at the end of class = 2^x Ln (3567+1) = x ln 2 Ln (3568)/ln 2 = x X = 11.8 So we need 12 bits (2^0 to 2^11) (base 2) = 3567 (base 10)

11 Counting in Binary/Octal/Decimal
Hexadecimal

12 Converting Binary to Hexadecimal
Mark groups of four (from right) Convert each group Note: We can use this method because hexadecimal (base 16) is a power of 2. 18

13 Converting Binary to Hexadecimal
Mark groups of four (from right) Convert each group A B is AB in base 16 18

14 Converting Binary to Octal
Mark groups of three (from right) Convert each group Note: We can use this method because octal (base 8) is a power of 2. 17

15 Converting Binary to Hexadecimal
Mark groups of four (from right) Convert each group A B is AB in base 16 18

16 Converting Decimal to Other Bases
Algorithm for converting number in base 10 to other bases While (the quotient is not zero) Divide the decimal number by the new base Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient 19

17 Converting Decimal to Hexadecimal
What is 3567 (base 10) in base 16? 32 15 Convert base 10 to base 2 then use the grouping method we just saw! Let’s Cheat!!! D E F 20

18 Converting Decimal to Octal
What is 1988 (base 10) in base 8? 64 4 Answer is : Convert base 10 to base 2 then use the grouping method we just saw!

19 Worksheet Question 2 Show your work Remember
Hexadecimal (grouping by 4) Octal (grouping by 3) = 2^x Ln (3567+1) = x ln 2 Ln (3568)/ln 2 = x X = 11.8 So we need 12 bits (2^0 to 2^11) (base 2) = 3567 (base 10)

20 Chapter 4 Data Representation

21 How many values can be represented in a byte?
What are the lowest and highest values? In binary (base 2)? In decimal (base 10)? What about 9 bits? What about 10 bits? What happens every time you increase the number of bits by one? 2^n = the number of unique values that can be represented in n bits

22 Binary Representations
Counting with binary bits Figure 3.4

23 2n = the number of unique values that can be represented in n bits

24 Worksheet Questions 3-5

25 Representing Images and Graphics
Color is expressed as an RGB (red-green-blue) value--three numbers that indicate the relative contribution of each of these three primary colors An RGB value of (255, 255, 0) maximizes the contribution of red and green, and minimizes the contribution of blue, which results in a bright yellow

26 Representing Images and Graphics
A few TrueColor RGB values and the colors they represent

27 Worksheet Question 6

28 Representing Text What must be provided to represent text?
There are a finite number of characters to represent, so list them all and assign each a binary string. Character set A list of characters and the codes used to represent each one Computer manufacturers agreed to standardize

29 The ASCII Character Set
American Standard Code for Information Interchange Originally used seven bits to represent each character, allowing for 128 unique characters Later extended ASCII evolved so that all eight bits were used

30 ASCII Character Set Mapping
Page 76 in your text

31 The ASCII Character Set
The first 32 characters in the ASCII character chart do not have a simple character representation to print to the screen What do you think they are used for?

32 The Unicode Character Set
Extended ASCII is not enough for international use One Unicode mapping uses 16 bits per character How many characters can this mapping represent? Unicode is a superset of ASCII The first 256 characters correspond exactly to the extended ASCII character set How many characters can this mapping represent? 2^16 = 65536

33 The Unicode Character Set
Figure 3.6 A few characters in the Unicode character set

34 Worksheet Questions 7-11 See page 76 in your text for ASCII character set

35 Text Compression Assigning 16 bits to each character in a document uses too much file space We need ways to store and transmit text efficiently Text compression techniques keyword encoding run-length encoding Huffman encoding  We will skip this one today but it is described in your text.

36 Keyword Encoding Replace frequently used words with a single character

37 Keyword Encoding Given the following paragraph,
We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. ム That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed, ム That whenever any Form of Government becomes destructive of these ends, it is the Right of the People to alter or to abolish it, and to institute new Government, laying its foundation on such principles and organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness.

38 Keyword Encoding The encoded paragraph is
We hold # truths to be self-evident, $ all men are created equal, $ ~y are endowed by ~ir Creator with certain unalienable Rights, $ among # are Life, Liberty + ~ pursuit of Happiness. — $ to secure # rights, Governments are instituted among Men, deriving ~ir just powers from ~ consent of ~ governed, — $ whenever any Form of Government becomes destructive of # ends, it is ~ Right of ~ People to alter or to abolish it, + to institute new Government, laying its foundation on such principles + organizing its powers in such form, ^ to ~m shall seem most likely to effect ~ir Safety + Happiness.

39 Keyword Encoding What did we save? Original paragraph 656 characters Encoded paragraph 596 characters Characters saved 60 characters Compression ratio 596/656 = Could we use this substitution chart for all text?

40 Run-Length Encoding A single character may be repeated over and over again in a long sequence Replace a repeated sequence with a flag character repeated character number of repetitions *n8 * is the flag character n is the repeated character 8 is the number of times n is repeated

41 Run-Length Encoding Original text bbbbbbbbjjjkllqqqqqq+++++
Encoded text *b8jjjkll*q6*+5 (Why isn't l encoded? J?) The compression ratio is 15/25 or .6 *x4*p4l*k7 xxxxpppplkkkkkkk This type of repetition doesn’t occur in English text; can you think of a situation where it might occur? There is no point in encoding sequences <= 3 because you need 3 characters to represent the sequence anyway (*, character, number of characters in sequence).

42 Worksheet Question 12

43 Huffman Encoding Why should the character “X" and "z" take up the same number of bits as "e" or " "? Huffman codes use variable-length bit strings to represent each character More frequently used letters have shorter strings to represent them

44 Huffman Encoding ballboard would be compression ratio 28/56
compression ratio 28/56 Encode roadbed

45 Huffman Encoding In Huffman encoding no character's bit string is the prefix of any other character's bit string To decode look for match left to right, bit by bit record letter when a match is found begin where you left off, going left to right

46 Huffman Encoding Try it! Decode

47 Huffman Encoding Technique for determining codes guarantees the prefix property of the codes Two types of codes general, based on use of letters in English (Spanish, ….) specialized, based on text itself or specific types of text


Download ppt "CSIS-110 Introduction to Computer Science"

Similar presentations


Ads by Google