Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Magic number (programming)


 Contents
In computer programming, a magic number is a special constant used for some specific purpose. It is called magic because its value or presence is inexplicable without some additional knowledge.

Magic numbers are often chosen based on (among others):

1 Magic numbers in files

An early convention in the Unix operating system was that ( binary) files started with two bytes containing a "magic number" identifying the type of the file. These were originally used by the Unix linker and loader. The concept has been expanded on over time, and is now in current use by many other programs across many operating systems. In a quick hack, the very earliest magic numbers were PDP-11 branch instruction s. The concept of magic numbers can be generalised to all files, since any unencoded binary data is essentially a number; most file formats can thus be identified by some signature that occurs somewhere in the file. Detecting such sequences is therefore an effective way of distinguishing between file formats - and can often yield further information at the same time.

Some examples:

The Unix command file can read and interpret magic numbers from files.



Read more »

Non User