File Extensions
Each file on a computer has a file name, often ending with a file extension. The extension tells the operating system which application to use when opening the file. It also gives users a hint about the file’s contents. For instance, Microsoft Word will open .docx
files, while .jpg
files are typically opened with image viewers. The computer normally adds the extension, but the user can also type in the extension when they name the file.
Warning: Always ensure that the extension matches the file type you are working with. An incorrect extension can prevent the file from opening. In certain classes, the instructors may specify a file type and naming convention. If you don’t turn in the correct file name, it may not get graded!
Malicious Use (Why you should always check extensions)
Some computers (primarily computers running Windows) may not always display the file extension to save screen space and make the file icons shorter and easier to read. Files can be named with extensions: for example, a file could be named funny.jpg
, but not be a .jpg
file. instead, its full name could be funny.jpg.exe
. The computer would think that the file is an executable (.exe
) file. If this file contains a virus, and you open it, thinking it’s an image, your computer could then be infected.
In Windows, to check a file’s type, right-click it and choose “Properties.” This will give you information about the file such as its size and what file type it is. You can also check the icon for the file type. The icon should match the expected file type (like an image icon for .jpg
). Virus protection software with real-time scanning will help prevent unwanted .exe files.
File Manipulation
A file is just a sequence of bytes. How those bytes are interpreted depends on the software used.
Consider the following image1.

If you open this image file (a .png
image) in a text editor like Notepad, TextEdit, or Nano, you’ll see strange characters. Here’s a portion of what it looks like on TextEdit.
âPNG
IHDR :2XWUFPLTEˇˇˇÉR“®QÊ≥?[:S6fi¥\ÇxdËΩ^fl¨B»¢Lˆ‚¥^N4èZ‚∫d^>,tN"÷ÆX¢zdä~d9& G/Ҕκ◊¨ ¿Öœî΃≠x
·¥
Ò‘*∂~
—õ ‚º«ätSóa§mÏ¥ÎÕ(¨ ¡ã
•r
Ûƒ≥y◊ñıΩ¥ìöwfl• Ÿ≥õfıÕ1πÉ ÌÃÚ∂
Your text editor shows the raw bytes that compose the file, which aren’t meant to be human-readable. Only image software (like Photoshop or Paint) knows how to render it as a picture.
You can edit the bytes of the image by typing in your text editor and saving the file. The result may still open as an image, but it may be corrupted or glitched. The graphics software translates the new information into the image. Here’s a changed Tux2.

Here’s the top of the text for the png
image. It is different, and the computer is interpreting it as an image. For most humans, this is not readable. But the two images are visually related and many humans can interpret the visual data.
âPNG
IHDR :ÜßgsRGBÆŒÈYiTXtXML:com.adobe.xmp<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.4.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
<tiff:Orientation>1</tiff:Orientation>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
L¬'Y@IDATxÏΩy\œk˜ˇ{ôEÑ$JQ2dHd,Iî!3°KIDÜîÃÛP “hñ!CÉπT"cTÊD%Q2&ûÁsŒπù«Ô{~ü˚~l?ªˆvÔ˜ü˚èkÍ£k]ØıZk=ó∏ú”Ö>>±|\[å≥a;¥C{ır]˙¯˚q-≈ŒÜ¥”•«◊À‰tÈÉOÏG÷;cÿNõ–_ëŒKflüÙ˜Ûfl}ѧ(=“¯üÄêѧ†$))ˡîAàˇA§")ÄHD¸ß"…Éë<(…Éí )ô∞í -ôˇ©!§*ÜT≈ë™XRÔ?U1≈ä Rëà@§"˛Së»iH√IÃ,¿2◊¡ú∏<ˇ˚∫o7éïÃQUK«’ è^ÅXº.ê˙`§>"Ñ‘Û_÷ì\´∫ÓÑ
Source Code vs. Machine Code
Applications are any program you run on your computer, for example:
- Microsoft Excel
- Firefox
- Notepad++
Programs (applications) are written in code. For example, Firefox.exe is a program that you can run on your computer. The code is available here. Notice that you run the program as Firefox.exe or Firefox.app, which doesn’t match the code structure.
Firefox’s code has changed over time! The original version, 2002, (from link) to 2016 (see link)!
We can see Firefox evolve over the years (although it didn’t take long for them to stop calling it Phoenix).
Source code is written by humans, compiled by the computer to produce machine code. After compiling, you now have an executable file that runs (or executes) – usually a .exe (Windows) or .app (Mac) file. An .exe or .app is a file, and so was the original source code.
Exercises
- Your colleague sent you a file named
report.dat
. When you try to open it with a text editor, it appears as gibberish, but when you try to open it with a spreadsheet program, it opens and shows organized columns of data. Based on your reading about file types, explain whatreport.dat
most likely is and why it behaved differently in each program. - How did I make the Tux image? I encrypted it (but not very well since you can still figure out the image). If you would like to try this yourself, try this lab! PDF link to lab instructions. To access the labtainer image, you’ll go to vcl.ncsu.edu and make a reservation for
CSC474-Labtainer
. (You can also spin up your own VM, if preferred: instructions). This lab does have one mistake in it, if you need to start Firefox from the terminal, type inexport DISPLAY=:10.0
before doing so and it should fix it. Report back with your findings.
References
- “Tux” (Larry Ewing lewing@isc.tamu.edu, The GIMP software) (rights) ↩︎
- ECB Penguin, Robert David Graham. ↩︎