magic number

(redirected from Magic constant)
Also found in: Dictionary, Thesaurus, Medical, Wikipedia.

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].
This article is provided by FOLDOC - Free Online Dictionary of Computing (

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).
Copyright © 1981-2019 by The Computer Language Company Inc. All Rights reserved. THIS DEFINITION IS FOR PERSONAL USE ONLY. All other reproduction is strictly prohibited without permission from the publisher.
References in periodicals archive ?
Note that [mathematical expression not reproducible] because the magic constant is k.
Of course, the magic constant is doubled too, because we are no longer using the numbers 1 to 9, but rather, 2 to 18 (see Figure 6).
The sum will always be our previously predicted 25, the magic constant of the square.
It can be checked that [f.sub.2] is an edge-magic labeling of [F.sub.2] with the magic constant 8(p + q) + 6m.
We guess that the (11,3)example is just the first of infinitely many such configurations.Specifically, for such (n,3) with n = 2m+1, m 5 or greater there existmagic configurations with magic constant K = 3(m+1).
3 8 1 6 2 3 5 7 1 4 9 2 a b c The magic constant sum on the rows, columns, and two main diagonals is 15 using the numbers 1 through 9.
This square is semimagic with magic constant DOUBLES MATCH on the rows and columns.
We have created a pandiagonal magic square with TOURMALINE as its magic constant. This extends the results found in Word Ways articles (1) and (2).