CS074: The Digital World

In-class Exercise with Binary Editor


1. If you have not already done so, download the Binary Editor from the course website into the course folder on your computer.  Make sure it is saved with with the file name BinEd.jar.  You should also download the test file telltale.txt that I have provided:  This is an ASCII-encoded text file of the creepy horror story "The Tell-Tale Heart", by Edgar Allan Poe. 

2. Launch the program by double-clicking on the icon with title BinEd.jar.

3. The first screen you see (the Save/Load screen) invites you to load a file.  Click on this button, then use the file chooser dialog box to navigate to where you saved telltale.txt, and select it.

You will be automatically switched to the Binary Editor screen.  At the right, you see the contents of the file, byte by byte, displayed in a number of different formats: decimal, hex, binary and, if the byte is the ASCII encoding of a character, text.  Observe that nonprinting and 'whitespace' ASCII characters like space, tab, and line feed (advancing to next line) are displayed using abbreviations.  If a byte is encountered that is not the ASCII encoding of a character, then question marks will be displayed.  This does not occur for the text file you are looking at, but is typical behavior when you examine other kinds of files, like images.

The left half of the screen contains a number of controls for modifying the bytes in  the file, as well as the total number of bytes, which in this case is 11176.  There are two ways to change the file contents:  by writing a kind of algebraic formula, or by using the controls Modify..., Average...,Copy/Delete.  Formulas give more flexibility, but are somewhat harder to learn.  Since we will be doing something very like the formula-writing later when we write programs, for the Binary Editor we will stick to the three control buttons just named.

4. Click on the Modify button and look at what comes up.  Let's experiment with some of these controls:  Suppose, for some reason or another, you wanted to change every occurrence of the lower-case letter 'e',  to #.  We need to know the ASCII encodings for   'e', and '#'.  We can look these up in the table provided in the course notes, and get the answers (in decimal) 101, and 35, respectively. So we use the controls to 'Set all cells with value in range 101 to 101 to 35', and click 'Apply'. You can see the effect clearly in the right-hand column.

5. This operation does NOT alter the saved copy of 'The Tell-Tale Heart' on your computer's hard disk.  To save your changes, you must click on the Save/Load tab, click 'Save As Binary File', and select a name to save the chnged file under.  I suggest that you keep the original version and save the changes as something like 'telltale2.txt'. Do this now, and then open the file you just saved in the Text Editor to examine the changes.

6. Now let's undo the changes by clicking 'Revert to Original', and let's try something new.  We are going to encrypt the text in the file by using a crude method.  We replace every occurrence of the letter 'a' by 'b', 'b' by 'c', etc., and similarly for the upper-case counterparts.  We replace 'z' and 'Z' by 'a' and 'A', respectively.  How do we use the controls in the Binary Editor to do this?  This is a multistep process:  An obvious answer is to start with  'increase all cells with values in the range 65 to 89 ('A' to 'Y') by 1, and then proceed to handle the lower-case letters, and then the z's.  But this will not work!  What is the right way to do this?

7. Now go back to the Save/Load screen and load the file 'flute.wav'.    We will talk at some length about how audio is encoded in computers.  For now you should just be aware that the bytes in this file (after the first 40 or so)  represent measures of amplitude, or signal strength, taken at intervals of 1/11025 sec.  If you plotted some of the sample values, they would look like this:


8.  Now switch to the Play As Sound screen and click Play.  (This should be fun in the class.) This plays back the sample values at 11025 samples per second, adjusting the volume in accordance with the byte value. 

9.  How can we modify the file to make the sound louder?  You can try to do this by adding a positive integer onto all the sample values, and also by multiplying all the sample values by, say, 1.5.  Try both of these.

10.  How can we make the sound play faster?  Try selecting every second sample, using the Average  control.

11. How can we simulate a change in the sample rate?  (Fewer samples per second.)  Try averaging every pair of successive samples, using the Average control.