int

Objective-C: How do you declare and retain an int?

Here's my code: @interface Game : Layer // this is from cocos2d { int maxSprites; } @implementation Game -(void)initVariables { maxSprites = 18; } Later on, when I print it out, NSLog(@" maxSprites = %d ", maxSprites); I get: maxSprites = 2 And operations that require it to be 18, crash or don't work, as if it's really ...

Objective-C: int value changing without cause

Objective-C: I need help retaining the value of an int. It's changing on me without my command. The original question was: "How do you declare and retain an int?", that was satisfied in another post here: http://stackoverflow.com/questions/1938513 Now I have a problem where an int that was 18 is changing to 2, somehow on its own. Her...

[java] String can't change. But int, char can change.

I've read that in Java an object of type String can't change. But int and char variables can. Why is it? Can you give me an example? Thank you. (I am a newer -_- ) ...

PHP - How to check that a string is an int, but not a double, etc.?

PHP has an intval() function that will convert a string to an integer. However I want to check that the string is an integer beforehand, so that I can give a helpful error message to the user if it's wrong. PHP has is_int(), but that returns false for string like "2". PHP has the is_numeric() function, but that will return true if the n...

What's the easiest way to convert a list of integers to a string of comma separated numbers in C#

I'm looking for the one liner here, starting with: int [] a = {1, 2, 3}; List<int> l = new List<int>(a); and ending up with String s = "1,2,3"; ...

Return first digit of an integer

How in Java do you return the first digit of an integer.? i.e. 345 Returns an int of 3. ...

Unary minus on a short becomes an int?

In the following: public class p { short? mID; short? dID; } short id = p.mID ?? -p.dID.Value; The compiler gives me the error: Error 21 Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?) I have to change the code to the following for it to work: short id = p.mID ?? (sh...

How to subtract two unsigned ints with wrap around or overflow

There are two unsigned ints (x and y) that need to be subtracted. x is always larger than y. However, both x and y can wrap around; for example, if they were both bytes, after 0xff comes 0x00. The problem case is if x wraps around, while y does not. Now x appears to be smaller than y. Luckily, x will not wrap around twice (only once is...

JSON to C# : convert an arraylist of doubles to an array of ints ?

I have an arraylist of doubles returned by a JSON library. After the JSON parser's decode method is run, we have this in the C# locals window: Name Value Type myObj Count=4 object {System.Collections.ArrayList} [0] 100.0 object {double} [1] 244.0 object {double} [2] 123.0 ...

Python, len, and size of ints

So, cPython (2.4) has some interesting behaviour when the length of something gets near to 1<<32 (the size of an int). r = xrange(1<<30) assert len(r) == 1<<30 is fine, but: r = xrange(1<<32) assert len(r) == 1<<32 ValueError: xrange object size cannot be reported`__len__() should return 0 <= outcome Alex's wowrange has this beha...

toString() of int e = 0000007 omits all zeros. How can I preserve them?

I'm trying to write a program in C# that takes in an int x and decides if it has exactly 7 digits. Right now I'm using x.toString().Length == 7 to check, but I noticed that if the number starts with 0, it automatically gets omitted and I get an incorrect answer (ie the program thinks the input length is less than 7) Is there a way to fi...

C# All math operations return as an integer?

Possible Duplicate: byte + byte = int why? I have a grid from (-1024,-1024) to (1024,1024), so I don't need all the values that an int provides, but I've noticed that all of my algorithms return as ints and I need to typecast them all with (short). Could anyone explain why all math operations return as int and is it more effec...

How is the __format__ method suposed to be used for int?

I saw there was a __format__ method but help(int.__format__) doesn't provide any help. I also know you're not suppose to call a __method__ directly. When is this method called? Which is its argument? ...

Java: InputStream read() returns a byte bigger than 127?

Hi, I've this code: InputStream is = socket.getInputStream(); int b; while ((b = is.read()) != -1) { System.out.println(b); } A byte its range is -128 until +127. But one of the printed bytes is 210. Is this the result of converting the read byte to an int? (So that the negatif byte becomes a positif int) If so, can I do the same...

Double to int conversion behind the scene?

I am just curious to know what happens behind the scene to convert a double to int, say int(5666.1) ? Is that going to be more expensive than a static_cast of a child class to parent? Since the representation of the int and double are fundamentally different is there going to be temporaries created during the process and expensive too. ...

Why does RandomAccessFile use int as offset

I am writing some data access test implementation and I need random access to file content. Here's the code: RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rwd"); final byte b[] = IOUtils.toByteArray(source); randomAccessFile.write(b, (int) offset, size); where offset has type long. Why doesn't RandomAccessFile provi...

C++ Confusion. Reading Integer From Text File. Convert to ASCII

I am learning C++ for the first time. I have no previous programming background. In the book I have I saw this example. #include <iostream> using::cout; using::endl; int main() { int x = 5; char y = char(x); cout << x << endl; cout << y << endl; return 0; } The example makes sense: print an integer and the AS...

how to find a address everytime.

i have been working on a server and it works with 2 programs i made one is the server and one is the error handler and if the main server fails it restarts it. the 2nd program's main way to handle data is by reading the values from the program(because when i was debugging i was filling in the address's), because writeing the values to a ...

It is possible to get an IntPtr from an int[] array?

Greetings. In C#: If I have an int[] array declared like this int[] array = new array[size]; there is an way to get the IntPtr from this array? The thing is that I'm using the EmguCV framework, and there is an constructor to create an image which takes an IntPtr to the pixel data, in order to build an image from an array (int[]). I...

Actionscript Build Hex String

Hi all, basically i want to build a colour hex value using 3 decimal values. for clarities sake, the 3 decimals i have are 255 254 253 and i want to generate the hex string: 0xFFFEFD how would i do that? ...