Magic numbers are unexplained values that often should be replaced with a named constant.
Questions tagged [magic-numbers]
193 questions
3
votes
2 answers
Finding magic numbers using NDepend
Does anyone know how I could find magic numbers in the source code using the CQL queries in NDepend? This is the same problem as this question, but I don't want to use regex if possible.
So I want to find all statements like
Int32 someValue =…

Joel in Gö
- 7,460
- 9
- 47
- 77
3
votes
1 answer
AIX/UNIX: module has an invalid magic number
On AIX, I am executing a script. In this script, it tries to load a 64 bit shared object lib ( .so file) . It fails to do so by giving the following error:
The module has an invalid magic number.
If I type "prtconf" it shows me that the system is…

AX_Que
- 31
- 1
- 4
3
votes
10 answers
Would These Be Considered Magic Numbers?
I've just completed writing a program for a programming class, and I want to avoid use of magic numbers, so here's my question:
In the function below, would my array indexers be considered magic numbers?
Code:
string CalcGrade(int s1, int s2, int…

Alex
- 64,178
- 48
- 151
- 180
3
votes
8 answers
Defining constants for 0 and 1
I was wondering whether others find it redundant to do something like this...
const double RESET_TIME = 0.0;
timeSinceWhatever = RESET_TIME;
rather than just doing
timeSinceWhatever = 0.0;
Do you find the first example to aid in readability? The…

Anonymous
- 4,167
- 11
- 47
- 52
3
votes
1 answer
How does this magic bit counting method work?
While working on the XKCD April Fool's skein hash collision problem I ran across this strange, fast, multiplicative method of counting the set bits in a word:
c = (v * 0x200040008001ULL & 0x111111111111111ULL) % 0xf;
Why does this work / what's…

Ternary
- 597
- 4
- 8
3
votes
2 answers
Avoiding magic strings and numbers
I am working on an application that has been edited by various programmers over the past few years and I have stumbled across a problem with using String Literals to access MenuItems.
For Example: in many places there is code…

jth41
- 3,808
- 9
- 59
- 109
3
votes
1 answer
Applet's .jar is messing up?
I'm trying to put an applet into a Google site (Because Domain hosting costs money). I've got that working, it is in the site. Now, I'm completely new to this, and my question is why doesn't my applet work?
The first thing I tried was uploading all…

SSaaM
- 108
- 10
2
votes
4 answers
How to see difference between WMA and WMV file with magic number detection?
I'm trying to sniff the type of a file, based on the magic numbers. After some googling I've found the following information:
WMA:
Primary association: Windows Media Company: Microsoft
Corporation File classification: Audio Mime type:
…

Kees C. Bakker
- 32,294
- 27
- 115
- 203
2
votes
3 answers
What config file format to use for user-friendly strings of arbitrary bytes?
So I made a short Python script to launch files in Windows with ambiguous extensions by examining their magic number/file signature first:
https://superuser.com/a/317927/13889
https://gist.github.com/1119561
I'd like to compile it to a .exe to…

endolith
- 25,479
- 34
- 128
- 192
2
votes
3 answers
ImportError: Bad magic number, since OSX Lion
I'm getting this error every time I run any python file in Eclipse using PyDev:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 73, in
__boot()
File…

Andrew Robertson
- 21
- 1
- 2
2
votes
1 answer
Magic number in files Linux. C programming
I want to get the Magic Number from a binary file (for example file ELF hava 7f 45 4c 46). I wrote a program to print out the magic number of the file but i get the error zsh: segmentation fault ./magic. How should I fix this?
int main()
{
…

Ivan Ivan
- 49
- 3
2
votes
1 answer
How to check type of files using the header file signature (magic numbers)?
By entering the file with its extension, my code succeeds to detect the type of the file from the "magic number".
magic_numbers = {'png': bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]),
'jpg': bytes([0xFF, 0xD8, 0xFF,…

Alya Mad
- 23
- 1
- 5
2
votes
2 answers
MVN Magic Number on switch
I´ve dealing with Checkstyle for a while and know what Magic Numbers are, however I´ve never encountered it this way, its just a Switch for assigning data, but the cases are marked as magic numbers, and I cant make those final or anything like that…

Frank de la torre
- 31
- 4
2
votes
1 answer
Tell if file is an image using .Net framework, not by checking magic numbers
With all the smarts of actually loading images being done by the .net framework, seems like I shouldn't have to repeat it all in my code by checking for magic numbers, or using a hack like this:
Private Function IsImage(FileName as String) As…

FastAl
- 6,194
- 2
- 36
- 60
2
votes
0 answers
Android "Bad magic number" error from readBundle
I've been using bundles to pass my information around my application and occasionally save them to a file by first passing them to a parcel.
For some reason occasionally when I try to put them back into a bundle it springs a "readBundle: bad magic…

isep
- 703
- 1
- 9
- 24