int

Way to get number of digits in an int?

Is there a neater way for getting the length of an int as this? int length = String.valueOf(1000).length(); ...

Add 2d int array to NSDictionary

Hello - I am new to Objective C and am having troubles adding a 2d int array to a NSMutableDictionary. The code errors with "incompatible pointer type" - I assume this is because setObject would be expecting an object.. Here is the code - I am trying to have a Dictionary containing my level data: NSMutableDictionary *level = [[NSMutabl...

Haskell converting Float to Int

I'm still new and trying to create a list for use in a function and want to keep it as small as possible which happens to be logBase x y. but I'm having trouble getting logBase into something I can use in this list. [1 .. (logBase x y)] Any suggestions? ...

Cast bool to T where T is int

How can I make this function reliably cast sourceValue to type T where sourceValue is bool and T is int? public static T ConvertTo<T>(Object sourceValue) { // IF IS OF THE SAME TYPE --> RETURN IMMEDIATELY if (sourceValue is T) return (T) sourceValue; var val = ConvertTo(sourceValue, typeof (T)); return (T) val; } Curren...

storing a value from an unsigned interger (2bytes long) to an unsigned char variable using bitwise operators?

How do I put the value of 0x04 in register 4 if the instruction was 1rxy? 1RXY-Load register R with the value at memory address XY #include <stdio.h> unsigned char r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,ra,rb,rc,rd,re,rf; void reg_check(unsigned char reg); void rxy1(unsigned char reg, unsigned char val); int main(){ unsigned char memloc1=...

Fixed-length integer datatypes

I have read of the Zero One Infinity rule in software design. Why is it called this? based on the actual behavior of software and its engineers, wouldn't this be better called the Zero One Two Billion One Hundred Forty-Seven Million Four Hundred Eighty-Three Thousand Six Hundred Forty-Eight rule, or perhaps the Zero One Four Billion Two...

Why do I have to assign a value to an int in C# when defaults to 0?

This works: class MyClass { int a; public MyClass() { int b = a; } } But this gives a compiler error ("Use of unassigned local variable 'a'"): class MyClass { public MyClass() { int a; int b = a; } } As far as I can tell this happens because in the first example, technically, the...

hex string to signed short int in c++

Hi, I could find the code to convert a hexadecimal string into a signed int (using strtol), but I can't find something for short int (2 bytes). Here' my piece of code : while (!sCurrentFile.eof() ) { getline (sCurrentFile,currentString); sOutputFile<<strtol(currentString.c_str(),NULL,16)<<endl; } My idea is to read a file with 2 byt...

Regex for matching ARGB Color (-44830298)

hey all, i'm trying to get Color information that i've stored in a text file and then use that color as the forecolor for a label. BUT, at run time when i click the button to do it, it doesnt give me any error messages or anything. the code i have is below: MatchCollection lines = Regex.Matches(File.ReadAllText(Path), @"(.+?)\r\n""([^...

strange malloc behavior in C

I am trying to create a matrix with dynamic proportions and to initialize it here is the code I am using to allocate memory and initialization: int **matrix; //mem allocation matrix=(int*)malloc(sizeof(int*)*mat_w); for (i=0;i<mat_w;i++) matrix[i]=(int)malloc(sizeof(int)*mat_h); //init for (i=0;i<mat_w;i++) for (j=0;j<mat_h;j++)...

How do I get the number of the item selected in a listbox (C#)

I'm trying to get the integer value of The number selected of the item. For example [Sample List Box] Beans Rice Can Potatoe [/Sample List Box] Rice is number 2 How can I do that in C#? ...

Is there an advantage on setting tinyint fields when I know that the value will not exceed 255?

Should I choose the smallest datatype possible, or if I am storing the value 1 for example, it doesn't matter what is the col datatype and the value will occupy the same memory size? The question is also, cuz I will always have to convert it and play around in the application. UPDATE I think that varchar(1) and varchar(50) is the sa...

how to CAST a double to int in C

I've got a double... say double d = 25.342; How can I get the 25 value? ( If it were -12.46 I'd like to get -13) Thanks! Manuel ...

C#: What's the best way to compare Double and Int?

Hello everybody, The following code in C# doesn't work: int iValue = 0; double dValue = 0.0; bool isEqual = iValue.Equals(dValue); So, the question: what's the best way to compare Double and Int? -- Best Regards, Murat ...

How do I declare a string without assigning a value in C++?

I know that for an integer, you can use: int value; I tried: string str; but Visual C++ gave me an error. How do I declare it without assigning a value, then using cin >> str later on to assign it? ...

Concatenating 2 2D arrays in java?

I've got 2 2D arrays, one int and one String, and I want them to appear one next to the other since they have the same number of rows. Is there a way to do this? I've thought about concatenating but that requires that they be the same type of array, so in that case, is there a way I could make my int array a String array? ...

Java Array Sort descending?

Is there any EASY way to sort an array in descending order like how they have a sort in ascending order in the Arrays class http://www.j2ee.me/javase/6/docs/api/java/util/Arrays.html ? Or do I have to stop being lazy and do this myself :[ ...

how to restrict an input in c

I want to prevent my program from any other types of input instead of int. How to check the type of an input without assigning it to a variable? in C ...

Java int division confusing me.

I am doing very simple int division and I am getting odd results. This code prints 2 as expected: public static void main(String[] args) { int i = 200; int hundNum = i / 100; System.out.println(hundNum); } This code prints 1 as not expected: public static void main(String[] args) { int i = 0200; int hundNum = i /...

Random MySQL row with PHP- low system resources.

I'm looking to get a random row from MySQL without using too much time or resources on the system. I don't care about weather the code given is PHP or MySQL based, however please note there are 'gaps' in my table. My table columns are 'id' (Primary key, auto increment), varchar, int, int I'd like it to be as random as possible ...