Magic numbers are unexplained values that often should be replaced with a named constant.
Questions tagged [magic-numbers]
193 questions
1
vote
1 answer
Boost Python Magic Number
I am trying to wrap some C++ functions for use in python. For example here is the function from the boost Python tutorial.
// Copyright Joel de Guzman 2002-2004. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file…

user2137072
- 11
- 2
1
vote
2 answers
Magic Numbers in C
I wanna use a magic number as a constant in checking that a memory block has not been violated, is there a method of "reverse-checking" to bring back the signature into the hexadecimal format of MAGIC_32BIT
#define MAGIC_32BIT 0x77A5844CU
int…

ryantata
- 137
- 1
- 3
- 12
1
vote
3 answers
Someone told me that it is saving memory to use numbers directly instead of static final int fields, is that true?
In my Android project, there are many constances to represent bundle extra keys, Handler's message arguments, dialog ids ant etc.
Someone in my team uses some normal number to do this, like:
handler.sendMessage(handler.obtainMessage(MESSAGE_OK, 1,…

yyyy_overflow
- 33
- 6
0
votes
2 answers
How to handle "simple" magic values?
I think this is fairly language-independent, but if I'm wrong, then go for C# (or C or C++).
With "simple" magic values I mean things like this:
if (Value > 0)
or
while (Value < 0)
or
while (MyQueue > 0)
While writing this (pseudo-code above) it…

Marcus Hansson
- 816
- 2
- 8
- 17
0
votes
0 answers
How can tzdata.zi file can be identified not as a .zi file Unambiguously?
I've got the tzdata.zi file (appears under the mcr.microsoft.com/dotnet/sdk:6.0 docker image).
From what I know it's a "zone info" file.
Unfortunately it got the same extension of .zi (which is also equivalent to zip file).
.zip file can be…

KaliTheGreat
- 579
- 6
- 17
0
votes
3 answers
Is there a standard way to define a big list of "magic numbers" or parameters?
Abstractly, say you were building a physics simulation and needed many universal constants or typical values for things like mass. It feels like there should be a standard approach to implementing this?
I'm mainly a hobbiest, using C++, and I can…

Tess
- 3
- 1
0
votes
1 answer
Jest magic number comparison failing in expect...toBe
I'm testing to ensure a Buffer's magic number is zip format.
I'm doing this by extracting the buffer's first 4 bytes to string and comparing against the magic number for zip which is PK.
const zipMagicNumber: string = 'PK'
const…

alyx
- 2,593
- 6
- 39
- 64
0
votes
1 answer
Preventing magic numbers used in firebase realtime database
So I want to specify a time after which a post gets deleted. The time is 3 months, in my code I would define this as
const THREE_MONTHS_IN_MS = 7889400000
export const TIME_AFTER_WHICH_USER_IS_DELETED = THREE_MONTHS_IN_MS
How can I define this in…

CaitlynCodr
- 238
- 1
- 15
0
votes
0 answers
Fast inverse square root in python on float32
I have done some checks for the fast inverse square root method in python (jupyterlab using python version 3.8.8) and for some reason then I've come to the conclusion that I must either be doing something wrong or there is something about float32…

Henrik
- 21
- 2
0
votes
0 answers
searches for files using the magic number of the file header
I'm doing an exercise: write a C program for Linux that searches for files in ELF, PE32, COFF and a.out formats using the magic number of the file header. I tried writing my own program to find magic number and it worked, however when I try to use…

Ivan Ivan
- 49
- 3
0
votes
2 answers
Incompatible magic value error
I was following an example from the following link:
http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html?page=1
and this is an output I am getting:
This program will use SimpleClassLoader.
>>>>>> Load class : TestClass
…

roman
- 21
- 1
- 1
- 2
0
votes
1 answer
How can we validate SVG Image without using magic number in AngularJS
We are currently validating images using magic number. Since SVG doesn't support magic number, what is the good way to validate SVG files in angularJS ?
This is how we are validating other images -
angular.module('fileMimeTypeServiceModule',…

Free-Minded
- 5,322
- 6
- 50
- 93
0
votes
0 answers
Getting rid of magic numbers in php array
Here's my code
$q->addNotInCondition('`t`.`id`', array(0, 1, 2));
I want to remove magic numbers in array. Is there a special way to do this or just define 0 , 1 and 2 ?
Is this correct?
const ONE= 4;
const TWO= 2;
const THREE=…

Sampath Wijesinghe
- 789
- 1
- 11
- 33
0
votes
2 answers
How to handle magic number in javascript
I have search through google with keyword handle javascript magic number but couldn't find one.
In c# i would used constant defined number but i don't know what to use in javascript
something like this
public class MagicNumberHelper
{
const int…

Sarawut Positwinyu
- 4,974
- 15
- 54
- 80
0
votes
1 answer
Magic number file checking
I'm attempting to read magic numbers/bytes to check the format of a file. Will reading a file byte by byte work in the same way on a Linux machine?
Edit: The following shows to get the magic bytes from a class file using an int. I'm trying to do the…

James P.
- 19,313
- 27
- 97
- 155