Governor's Career & Technical Academy Arlington

CSC 221 Weekly Assignments: Week 14

CSC 221


Overview

I was disappointed the day before Thanksgiving when (as I told you several times during class that I would) I evaluated your file reader mini-projects. Many of you have not made a single commit to your git repos in weeks.

This week we will begin a unit and do a project together that will hopefully get you back on track. We will learn about bitwise operators and finish by completing a project to encode binary files in Base64.

Friday, December 1st

Classwork

Today in class we will explore two new Python datatypes, bytes and bytearrays. We will be using these datatypes to work with binary data.

We will then form groups of four people for the project we will do next week.

The following Python shell session will get us started:

>>> mybytes = bytearray([65, 20, 42])
>>> mybytes
bytearray(b'A\x14*')
>>> my_immutable_bytes = bytes([65, 20, 42])
>>> my_immutable_bytes
b'A\x14*'
>>>

These two built-in Python sequence types, bytes and bytearrays give us immutable and mutable strings of byte-sized characters respectively. To see the difference, let's look at the following:

>>> mybytes[2]
42
>>> my_immutable_bytes[2]
42
>>> mybytes[2] = 43
>>> mybytes
bytearray(b'A\x14+')
>>> my_immutable_bytes[2] = 43
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'bytes' object does not support item assignment
>>>

These two new data types provide us with a wonderful opportunity to review some important Python concepts:

  • sequence types
  • mutable vs immutable data types

Homework

Do a web search for information on Base64 encoding, paying particular attention to references to RFC 4648.

Come to class on Tuesday ready to answer a few questions about what Base64 encoding it and why it was created on a short quiz at the beginning of class.

Resource

Wednesday, November 29th

Classwork

We will begin class with a short quiz on binary numbers, and then discuss the two other number representations (octal and hexadecimal) commonly used with computers.

I will do a brief demo of the bitwise operators available in Python, which you will then explore further in your homework.

Homework

Create a file in your AllJustBits directory named file named BitwiseMath.md. Watch the following two video lessons, taking notes in this file:

  1. Bitwise Math
  2. Number Representations

Monday, November 27th

Classwork

I will begin class giving you feedback on my mini-project evaluation, and make suggestions as to how to improve your git repos with a goal of making them part of your personal e-portfolios (reminder: ask student voluteer to demo a clean-up).

I will then share a remix of Luka and Jonathan's data reading project.

Finally, I will briefly review binary numbers, with which you will need to become very comfortable as you continue your study of computer science.

Homework

Create a directory in your git respository named AllJustBits. edit a markdown file named BinaryNumbers.md. Watch the following two video lessons, taking notes in this file:

  1. Binary, Bytes, and Bitwise Operators in Python (Overview)
  2. Binary Numbers

Shout Outs

The shoutout for most amazing, exemplary version of this mini-project belongs to Luka and Jonathan. We will study their solution together in class. To make that easier, I have grabbed a version and put it here.

Several others did a bang-up job on this mini-project:

And others almost hit the mark:

NOTE: We have the strong possibility here of a free-rider problem. In all future pair projects, each of the pairs will be responsible for including the project code in their own respository.