Here, we refer to magic numbers for different file types. It specifies the first few bytes of a file that are used to uniquely distinguish other file types. With these magic numbers, we can easily differentiate different files, which makes programming easier, because I reduce the time it takes for us to differentiate the file type of a file.
For example, some bytes starting with a jpeg file may be similar to this"Ffd8 ffe0 0010 4a46 4946 0001 0101 ...... Jfif ..... G", Here"Ffd8"It indicates that this file is a jpeg file ,"Ffe0"Indicates that this is a jfif type structure.
The following example shows some common file types, as well as several starting bytes used to determine the file type and the ASCII numbers on the pointed point:
Image files
File Type |
Extension |
Hexadecimal number XX indicates the variable. |
ASCII number . = Not ASCII characters |
Bitmap format |
. BMP |
42 4D |
BM |
Fits format |
. Fits |
53 49 4D 50 4C 45 |
Simple |
GIF format |
. Gif |
47 49 46 38 |
Gif8 |
Graphics Kernel System |
. GKS |
47 4B 53 4D |
Gksm |
Iris RGB format |
. RGB |
01 da |
.. |
ITC (cmu wm) Format |
. ITC |
F1 00 40 bb |
.... |
JPEG file Interchange Format |
. Jpg |
FF D8 FF E0 |
.... |
NIF (Navy TIFF) |
. NIF |
49 49 4E 31 |
Iin1 |
PM format |
. PM |
56 49 45 57 |
View |
PNG format |
. PNG |
89 50 4E 47 |
. PNG |
Postscript format |
. [E] PS |
25 21 |
%! |
Sun rasterfile |
. RAS |
59 A6 6a 95 |
Y. J. |
Targa format |
. TGA |
Xx |
... |
Tiff format (Motorola-big endian) |
. Tif |
4d 4D 00 2a |
Mm .* |
Tiff format (Intel-little endian) |
. Tif |
49 49 2a 00 |
II *. |
X11 bitmap format |
. Xbm |
Xx |
|
Xcf gimp file structure |
. Xcf |
67 69 6D 70 20 78 63 66 20 76 |
Gimp xcf |
Xfig format |
. Fig |
23 46 49 47 |
# Fig |
XPM format |
. XPM |
2f 2a 20 58 50 4D 20 2a 2f |
/* XPM */ |
Compressed file
File Type |
Extension |
Hexadecimal number XX indicates the variable. |
ASCII number . = Not ASCII characters |
Bzip |
. Bz |
42 5A |
BZ |
Compress |
. Z |
1f 9d |
.. |
GZIP format |
. GZ |
1f 8b |
.. |
PKZIP format |
. Zip |
50 4B 03 04 |
PK .. |
Archive files
File Type |
Extension |
Hexadecimal number XX indicates the variable. |
ASCII number . = Not ASCII characters |
Tar (pre-POSIX) |
. Tar |
Xx |
(A filename) |
Tar (POSIX) |
. Tar |
75 73 74 61 72 |
USTAR (offset by 257 bytes) |
Executable files
File Type |
Extension |
Hexadecimal number XX indicates the variable. |
ASCII number . = Not ASCII characters |
MS-DOS, OS/2 or MS windows |
|
4d 5A |
MZ |
UNIX elf |
|
7f 45 4C 46 |
. Elf |
Other files
File Type |
Extension |
Hexadecimal number XX indicates the variable. |
ASCII number . = Not ASCII characters |
PGP Public Ring |
|
99 00 |
.. |
PGP security ring |
|
95 01 |
.. |
PGP security ring |
|
95 00 |
.. |
PGP encrypted data |
|
A6 00 |
Invalid. |