Part of Lesson Plan: B8- Peeking Inside a Computer File- Using a Hex Editor
Activity Overview / Details
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.