Part of Unit: Operating Systems
Lesson Plan Overview / Details
Sometimes it is useful to be able to look at a computer file at the actual byte level. Hexadecimal editors allow us to do exactly that. This lesson teaches students how to use a hex editor and advanced text editor called Notepad++. It then shows what important hidden file aspects these tools reveal.
Activities in this Lesson
- Hook Activity - Hooks / Set
Before class begins, prepare a number of “Black Boxes”. These will be small, sealed boxes with unknown items in them. Students will attempt to guess what is in the boxes based on their observations.
You will need a black box and a magnet for each group. Usually 6-10 is fine. The box should be small enough to be held in the hand, but large enough to hold the items where they can shake around a little bit and make noise. My black boxes are about 3”x3”x2” and that is a comfortable size for this lesson. The exact size of the black boxes is not important. The best place to get your black boxes is a local jewelry store. Ring boxes are a little small, but small necklace boxes are just about right. I found that when I explained what I was using them for, the jeweler gave them to me for free!
Put several small items in each box, with one item being magnetic. The best combination I have found is a metal washer, a marble and a dice. You can experiment to find what is best for you. I put identical objects in each box, but you may want to vary that.
Seal the boxes tight. Glue them shut and if necessary, tape them. If the boxes are not very tightly secured, there is always, in my experience, at least one group who will try to peek. Unfortunately, this usually destroys the box and then you have to make a new one. If the box looks impenetrable from the beginning, it usually stops such nonsense.
Have the students put their name on a sheet of paper and title it “Black Box Lab”. Hold up a black box and explain that their job will be to guess what is in it without opening it. Explain that this is similar to how we often have to troubleshoot a problem computer files. We are not able to “look inside the box” because we can’t see inside a file so we must figure out how to poke and prod from the outside until we can guess what is going on in the inside.
Before you even give out the boxes, have them write down some tests they could perform to help them determine what is in the box. Their tests might include shaking the box, turning it slowly, spinning it, weighing it or any number of other ideas. Encourage them to be creative!
Now pass out the boxes and have them perform the tests they have devised, writing down the results they get from the test. Have them try to make up new tests now that they have had a chance to work with the boxes. Explain to them that this is the way real diagnostics works- doing one thing may give them an idea for another.
Now ask them if they can think of any tools that they might be able to use that would help them determine what is in the box without opening it. Something that could “look inside” the box. Have them write these tools down. They probably thought of an X-ray machine or something like that. Explain that you don’t have an X-ray machine, as much as that would help, but you do have something that can “see” inside the box. Hand out the magnets and tell them that the magnetic field can penetrate into the box where their eyes can’t and give them information. With practice, they should be able to use the magnet to hold the washer in place so they can listen to the rolling of the marble and the sliding of the dice. I usually have a few groups that figure out what is in the box. Have them finish writing up their results and best guesses about the contents of the box and turn the write-up in.
- Lecture - Lecture
Computer files are sometimes a “black box” to us. We see what they do, but really can’t see what’s happening inside. This makes it hard to fix them when something goes wrong. But there are many tools out there that can help us “see inside” a computer file to help us see what is wrong.
The first tool that can help is called Notepad++. It is a free program that is readily available on the internet. It is a program used by programmers because it creates text documents for programming purposes and also gives much greater control over hidden programming markers in a file. You can download it here: http://notepad-plus-plus.org/You can have the program already pre-installed on student computers or use this time as an opportunity to walk the students through the process of looking up a program, determining the latest version and downloading and installing.
Another type of program is called a “hex editor”. These programs allow you to look at a file in original hexadecimal notation. This allows you to see ALL of the bytes in the file, even the hidden ones. You can edit a file in a hex editor, but it is risky. Mostly, hex editors are useful in allowing you to see deeply inside a file to see potential problems. There are many hex editors out there, but my favorite is HxD. You can download it here: http://mh-nexus.de/en/hxd/ . This program has some real advantages. It has a portable version, so it can does not need to be installed on the computer to work. You can even download it to a flash drive and use it from there.
- Demonstration of skills - Demo / Modeling
One place where a hex editor is very useful is determining End Of Line (EOL) settings. When an operating system makes a text file, there are hidden markers that tell it when a line ends so it will know to start the next line. Unfortunately, different operating systems use different markers for this. Windows uses two markers, 0D and 0A. The first tells it to return to the beginning of the text row, the second tells it to go down a row. Unix, on the other hand, uses only one marker, 0A, to do both.
Let’s see how this works. I have provided two files for you, “File_Windows.txt” and “File_Unix.txt”. The files have identical text, but one is formatted using Windows EOL markers and the other uses Unix EOL markers. Open both of these files with HxD and find the EOL markers in the hexadecimal. You should see something that looks like the image I have provided, “Windows_Unix_EOL.jpg”.
If possible, have the students download the files and follow along. Open the files in HxD and compare the EOL markers. Then open the files in Notepad++ and convert the EOL markers from Windows to Unix and back. You can do this using the Edit => EOL Conversion setting. Refer to the picture “NotePad_EOL.jpg”.
By now the students should have noticed that there also is a “Mac” EOL setting. Have them convert one of the files to Mac EOL and tell you what the EOL code is.
Why is this important? In some situations, computer code written using a certain EOL marker will not work properly and the code must be converted to another format. A prime example is Perl scripts. I teach Perl, a programming language to run web servers. Perl scripts written using Windows EOL markers will not work. They must be converted to Unix format or they will seize up the server! It took me a week to figure this out. The scripts looked identical until I opened them in a hex editor. I researched and found out that the 0D marker was read by Perl as a different command that locked it up.
- Windows File [ Download ] Windows File
- Unix File [ Download ] Unix File
- Windows_Unix_EOL.jpg [ View Image ] [ Download Original ] Windows_Unix_EOL.jpg
- NotePad_EOL.jpg [ View Image ] [ Download Original ] NotePad_EOL.jpg
- Check for Understanding - Check Understanding
Explain the problems I discussed in the last section with Perl scripts. Ask the students, “How would it have worked if the Perl scripts were in Mac format?”
- Lab Activity - Lab / Shop
A good hex editor will allow a student to edit a file directly in hexadecimal. This usually is very dangerous, as it can overwrite important command code. However, with a simple text document there is no problem. Have the students make a simple text document and then edit it in the hex editor. Then have them open the document in Notepad++ and see the changes they have made. Check that they have performed this task with a check sheet.
Now have them take the text document they created and open it in a word processor like Word. Have them re-save the document as a Word document. Now have them open the document with Notepad++ and compare what they see with what was in the original text. They should see a large amount of computer code written by the word processor to keep the formatting of the document. Have them print out a sample page or two of the word processing code and try to figure out what it means. They should be able to figure out a little of it! Have them write notes on the page of what they think the code is doing, put their name on the paper and hand it in. Now have them open the same document in HxD and compare what they see.
- Closing Activity - Closure
There is a story told about a mathematician, an engineer, a physicist and a computer programmer who were driving in a car together to a conference. The car had a flat tire and they got out to try to figure out what to do.
The mathematician said, “I think I see the problem. The tire is no longer round on the bottom. But what can we do to fix it?”
The physicist replied, “the solution is obvious. The tire is still round on the top. What we need to do is jack up the car, turn the tire over so the round part is on the bottom and we can be on our way.”
The engineer sad, “That won’t work! We should jack up the car, take off the tire and replace it with another tire. Then we can be on our way.”
The computer programmer thought for a minute and said, “Why don’t we treat it like a computer? Let’s just turn the car completely off for a minute, drink a cup of coffee, start it back up and see if the problem fixes itself!”
This is how we sometimes feel when working with computers. Whatever goes on inside is very mysterious, so we just try whatever we can think to do “from the outside” and hope it works. Hopefully, these programs we have used today will help you feel like you know a little more what goes on inside a computer.
- Assessment - Assessment
Assessment should be based on the Black Box Lab, the Notepad printout and point assigned for participation.
Student Objectives / Goals
- Students will understand the importance of being able to view computer files in the original hexadecimal format.
- Students will understand that computer files have hidden markers that affect their performance.
- Students will understand the importance of using powerful tools to investigate phenomenon.




