magic number

Also found in: Dictionary, Thesaurus, Medical, Wikipedia.
Related to magic number: Golden number

magic number

(jargon, programming)
1. In source code, some non-obvious constant whose value is significant to the operation of a program and that is inserted inconspicuously in-line (hard-coded), rather than expanded in by a symbol set by a commented "#define". Magic numbers in this sense are bad style.

2. A number that encodes critical information used in an algorithm in some opaque way. The classic examples of these are the numbers used in hash or CRC functions or the coefficients in a linear congruential generator for pseudorandom numbers. This sense actually predates, and was ancestral to, the more common sense 1.

3. Special data located at the beginning of a binary data file to indicate its type to a utility. Under Unix, the system and various applications programs (especially the linker) distinguish between types of executable file by looking for a magic number. Once upon a time, these magic numbers were PDP-11 branch instructions that skipped over header data to the start of executable code; 0407, for example, was octal for "branch 16 bytes relative". Nowadays only a wizard knows the spells to create magic numbers. MS DOS executables begin with the magic string "MZ".

*The* magic number, on the other hand, is 7+/-2. The paper cited below established the number of distinct items (such as numeric digits) that humans can hold in short-term memory. Among other things, this strongly influenced the interface design of the phone system.

["The magical number seven, plus or minus two: some limits on our capacity for processing information", George Miller, in the "Psychological Review" 63:81-97, 1956].

magic number

In programming, a magic number is a constant value used to identify a file format, protocol or error code. In many file formats, the first few bytes identify the file; for example, "PK" in ZIP files and the hex values "F8 D8" in JPEG files.

Certain communications protocols use a magic number, such as the hex values "63 82 53 63" at the start of every DHCP packet or "FF 53 4D 42" at the beginning of every SMB request. See DHCP and SMB.

Magic Constants
The term also refers to fixed values in a program that are never expected to change. For example, an algorithm involving playing cards might frequently use the magic constant "52" without jokers or "54" with jokers (or "51" and "53" for offset addresses).
References in periodicals archive ?
Rakuten saw its winning streak snapped at six games and had its magic number to clinch a playoff spot disappear.
Hitoshi Taneda ignited the offense with a two-run double in the second inning and Daisuke Miura (9-8) pitched eight strong innings as Yokohama handed Chunichi its fifth loss in six games, giving the idle Tigers the magic number of 13.
Here Tran goes for pure dance, with three as the magic number: three dancers, three sections, counts of three.
Twenty million litres of ethanol is the magic number right now, according to the study conducted by Eco Cinergie.
THE MAGIC NUMBER: 38 JAMES HUNTER SUNDERLAND'S win at Everton has changed the complexion of the relegation battle.
Phil Moore, who drives a seven-year old Volvo FM tag-axle six-wheeler, achieved the magic number while returning from a delivery to Holland recently.
9 MILLION AND COUNTING NINE million is the magic number for Microsoft right now, after the software giant revealed the staggering total of Xbox 360 consoles that have been sold to date in Europe alone.
THREE is most definitely the magic number for 27-year old Shane West.
A number of other Irish players namely, John Hayes (48), Ronan O'Gara (47) and Peter Stringer (46), should reach the magic number in the coming weeks.
Five is a magic number in this context because entanglement of that many or more photons or other particles would enable a future quantum computer to find and eliminate random errors in its data, Pan says.