cantonada cantonada

Magic number

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.

Some examples:

* Compiled Java class files (bytecode) start with 0xCAFEBABE on big-endian systems.
* GIF image files have the ASCII code for 'GIF89a' (0x474946383961) or 'GIF87a' (0x474946383761)
* JPEG image files have the ASCII code for 'JFIF' (0x4A464946) followed by more metadata about the file.
* PNG image files begin with an 8-byte signature which identifies the file as a PNG file and allows immediate detection of some common file-transfer problems: \211 P N G \r \n \032 \n (0x89504e470d0a1a0a)


* Standard MIDI music files have the ASCII code for 'MThd' (0x4D546864) followed by more metadata about the file.
* Unix script files usually start with a shebang, '#!' (0x2321, or 0x2123 on little-endian processors) followed by the path to an interpreter.
* Old MS-DOS .exe files and the newer Microsoft Windows PE (Portable Executable) .exe files start with the ASCII string 'MZ' (0x4D5A), the initials of the designer of the file format, Mark Zbikowski.
* The Berkeley Fast File System superblock format is identified as either 0x19540119 or 0x011954 depending on version; both represent the birthday of author Marshall Kirk McKusick.
* Executables for the Game Boy and Game Boy Advance handheld video game systems have a 48-byte or 156-byte magic number, respectively, at a fixed spot in the header. This magic number encodes a bitmap of the Nintendo logo.
* Old Fat binaries (containing code for both 68K processors and PowerPC processors) on Mac OS 9 contained the ASCII code for 'Joy!' (0x4A6F7921) as a prefix.

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

Source: www.wikipedia.org

Go to the Main Web

Print.../ Send to:
Google