integer

C# newbie problem with variable types

int newWidth = 100; int newHeight = 100; double ratio = 0; if (img1.Width > img1.Height) { ratio = img1.Width / img1.Height; newHeight = (int)(newHeight / ratio); } else { ratio = img1.Height / img1.Width; newWidth = (int)(newWidth / ratio); } Image bmp1 = img1.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero); ...

NSUserDefaults limit integer?

Hey guys, Is it possible to limit an integer in the NSUserDefaults? Off course you can limit it within your app but I am thinking of the TextFields in Settings. Would be great to get some hints. Thanks a lot. ...

Why is abs(0x80000000) == 0x80000000?

I just started reading Hacker's Delight and it defines abs(-231) as -231. Why is that? I tried printf("%x", abs(0x80000000)) on a few different systems and I get back 0x80000000 on all of them. ...

Is there a way in .Net to get a string value for an int's word?

For example: (1).SomeFunction().Equals("one") (2).SomeFunction().Equals("two") I really only need it for digits 1-9 in the case I'm working with, should I just use a switch/select case? Update I won't need localization in this case either. Update 2 Here's what I ended up using: Private Enum EnglishDigit As Integer zero one ...

In python, what is the fastest way to determine if a string is an email or an integer?

I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks. def __init__(self, data): #populate class data self._fetchInfo(data) def _fetc...

c++ floating point to integer type conversions

What are the different techniques for a floating point type to an integer type conversion, in c++? ...

What's the difference between unsigned long/long/int in c/c++?

It seems all of them take 4 bytes of space, so what's the difference? ...

PHP: Shortest way to check if a variable contains positive integer?

I want to check if user input a positive integer number. 1 = true +10 = true .1 = false -1 = false 10.5 = false Just a positive number. No characters. No special character. No dot. No minus sign. I tried is_int() function but it is returning false even on positive integers. Is there a string to int problem? Thanks ...

Question about variable definitions in functions.

Hi. #include <stdio.h> main() { int a; for(a=1; a<=4 && printf("%d ",a); a++) { int a; static int b=a; printf("%d ",(a++)-b); } getchar(); getchar(); } In this code, the printout is 1 0 2 1 3 2 4 3. I understand why the int a; part works differently than the int a which was defined ou...

PHP validating integers

Hi, I was wondering, what would be the best way to validate an integer. I'd like this to work with strings as well, so I could to something like (string)+00003 -> (int)3 (valid) (string)-027 -> (int)-27 (valid) (int)33 -> (int)33 (valid) (string)'33a' -> (FALSE) (invalid) That is what i've go so far: function parseInt($int){ /...

How do I do modulus in C++?

How do I perform a mod operation between two integers in C++? ...

SQlite: Column format for unix timestamp; Integer types

Original problem: What is the right column format for a unix timestamp? The net is full of confusion: some posts claim SQLite has no unsigned types - either whatsoever, or with exception of the 64bit int type (but there are (counter-)examples that invoke UNSIGNED INTEGER). The data types page mentions it only in a bigint example. It als...

What's a good way to detect wrap-around in a fixed-width message counter?

I'm writing a client application to communicate with a server program via UDP. The client periodically makes requests for data and needs to use the most recent server response. The request message has a 16-bit unsigned counter field that is echoed by the server so I can pair requests with server responses. Since it's UDP, I have to ha...

Why can't the compiler/JVM just make autoboxing "just work"?

Autoboxing is rather scary. While I fully understand the difference between == and .equals I can't but help have the follow bug the hell out of me: final List<Integer> foo = Arrays.asList(1, 1000); final List<Integer> bar = Arrays.asList(1, 1000); System.out.println(foo.get(0) == bar.get(0)); System.out.println(foo.get(...

Converting string expression to Integer Value using C#

Sorry if this question is answered already, but I didn't find a suitable answer. I am having a string expression in C# which I need to convert to an int or decimal value. For example: string strExp = "10+20+30"; the output should be 60. how shall I do that??? ...

IPhone SDK Default NSUserDefaults...

I have set up the user defaults to record a integer for a UISlider, the problem is that, if the user has only just installed the app then the integer is zero or NULL. Is there a way to detect if it = NULL with a integer? heres my code i have so far: -(void)awakeFromNib { NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; se...

Division to the nearest 1 decimal place without floating point math?

I am having some speed issues with my C# program and identified that this percentage calculation is causing a slow down. The calculation is simply n/d * 100. Both the numerator and denominator can be any integer number. The numerator can never be greater than the denominator and is never negative. Therefore, the result is always from ...

Faster integer division when denominator is known?

hi I am working on GPU device which has very high division integer latency, several hundred cycles. I am looking to optimize divisions. All divisions by denominator which is in a set { 1,3,6,10 }, however numerator is a runtime positive value, roughly 32000 or less. due to memory constraints, lookup table may not be a good option. Ca...

Remove integers in array less than X with PHP

Hello. I have an array with integers of values from 0 to 100. I wish to remove integers that are less than number X and keep the ones that are equal or greater than number X. I am using PHP. Thanks! ...

Python: finding lowest integer

I have the following code: l = ['-1.2', '0.0', '1'] x = 100.0 for i in l: if i < x: x = i print x The code should find the lowest value in my list (-1.2) but instead when i print 'x' it finds the value is still 100.0 Where is my code going wrong? ...