integer

Why is a cast required for byte subtraction in C#?

I have to following code in VS2008 .net 3.5 using WinForms: byte percent = 70; byte zero = 0; Bitmap copy = (Bitmap)image1.Clone(); ... Color oColor = copy.GetPixel(x, y); byte oR = (byte)(oColor.R - percent < zero ? zero : oColor.R - percent); When I leave the "(byte)" off the last line of code, I get a compiler error saying it "Ca...

How can I fix an int-to-bool warning in C++?

I get a warning in MSVC++ when I try to read an integer from a file and make a bool variable equal it. accessLV[i] = FileRead(file1, i + 1); (accessLV is an array of bools, FileRead is a function I made to decrease the syntax involved in reading from a file, i is because the statement is within a for loop) I've tried using a static_c...

Modulo in JavaScript - large number

Hi! I try to calculate with JS' modulo function, but don't get the right result (which should be 1). Here is a hardcoded piece of code. var checkSum = 210501700012345678131468; alert(checkSum % 97); Result: 66 Whats the problem here? Regards, Benedikt ...

In C# what type are integer literals?

I just notice if i pass a value such as 1 in a function parameter it will work if it excepts int, long and i assume the others. However if i do int i = value, it doesnt. I was wondering, what type is it? ...

ArrayList of Integers to one int?

what would be the easiest way to convert an ArrayList of Integers to one int, with the 1st Integer in the list being the 1st number in the int, etc. in Java? For example an ArrayList of Integers: 1 4 6 7 8 3 8 becomes the int value 1467838 ...

Java: Integer value comparison

I'm a newbie Java coder and I just read a variable of an integer class can be described 3 different ways in the api. I have the following code.. if (count.compareTo(0)) { System.out.println(out_table); count++; } This is inside a loop and just outputs out_table. My goal is the figure out how to see if th...

Converting between types in Objective-C

Being a starting Objective-C developer, and not having the patience to actually do some studying, rather than just diving into things, I ran into the following: I have a CGFloat, and I want to divide it by something, and use the result as an NSInteger. Example: CGPoint p = scrollView.contentOffset; //where p is a CGFloat by nature NSI...

php hash form string to integer

Does PHP have a built in function for doing string to integer hashes, something that's difficult to reverse? Now, I know I can probably get away with doing an md5, and treating a substring of it as a radix 16 number, but I'm looking for something built in. Thanks. ...

09 is not recognized where as 9 is recognized

I am using quartz for schedulling. TriggerUtils.getDateOf(0,40,18,09,06); it accept 5 parameter. (seconds, minutes, hours, daysOfMonth, month). When i pass fourth parameter as "09". Eclipse give me error "The literal Octal 09 (digit 9) of type int is out of range ". But when i pass the fourth parameter as "9" instead of "09", it work...

Is there an equivalent to JavaScript parseInt in C#?

I was wondering if anyone had put together something or had seen something equivalent to the JavaScript parseInt for C#. Specifically, i'm looking to take a string like: 123abc4567890 and return only the first valid integer 123 I have a static method I've used that will return only the numbers: public static int ParseInteger( obj...

PHP: intval() equivalent for numbers >= 2147483647

Hello! In PHP 5, I use intval() whenever I get numbers as an input. This way, I want to ensure that I get no strings or floating numbers. My input numbers should all be in whole numbers. But when I get numbers >= 2147483647, the signed integer limit is crossed. What can I do to have an intval() equivalent for numbers in all sizes? Her...

How to convert DateTime to a number with a precision greater than days in T-SQL?

Both queries below translates to the same number SELECT CONVERT(bigint,CONVERT(datetime,'2009-06-15 15:00:00')) SELECT CAST(CONVERT(datetime,'2009-06-15 23:01:00') as bigint) Result 39978 39978 The generated number will be different only if the days are different. There is any way to convert the DateTime to a more precise number, a...

Handle either a list or single integer as an argument

A function should select rows in a table based on the row name (column 2 in this case). It should be able to take either a single name or a list of names as arguments and handle them correctly. This is what I have now, but ideally there wouldn't be this duplicated code and something like exceptions would be used intelligently to choose ...

Why don't I declare NSInteger with a *

I'm trying my hand at the iPhone course from Stanford on iTunes U and I'm a bit confused about pointers. In the first assignment, I tried doing something like this NSString *processName = [[NSProcessInfo processInfo] processName]; NSInteger *processID = [[NSProcessInfo processInfo] processIdentifier]; Which generated an error, after t...

Fastest way of checking the condition l+1<r for int l,r in Java

What is the fastest way of checking the condition l + 1 < r for int l,r in Java? l and r are not constant and I know that l <= r. The comparison is a stopping condition for a while loop in a binary search implementation. I am of course benchmarking my code, both in a separate test (searching a large array) and in the code which uses ...

Print an int in binary representation using C

Hi All, I'm looking for a function to allow me to print the binary representation of an int. What I have so far is; char *int2bin(int a) { char *str,*tmp; int cnt = 31; str = (char *) malloc(33); /*32 + 1 , because its a 32 bit bin number*/ tmp = str; while ( cnt > -1 ){ str[cnt]= '0'; cnt --; } cnt = 31; while (a >...

How can I left-pad the string representation of a float?

Hello. I'm trying to convert a single precision floating point number into an ascii representation of the four bytes that make it (sign/exponent/mantissa). My current code is: Integer.toString(Float.floatToRawIntBits(f),16); Float.floatToRawIntBits makes an integer using the same bytes, and then Integer.toString creates the ascii dig...

Converting int to string in PHP

Is there a way to convert integers to string in PHP? ...

Unable to increase AWK's int-limit for factorial

I run the AWK code and I get The factorial of 200 is inf This suggests me that AWK does not use the same int IEEE-standard -module as Python. It seems that AWK's limit is 170!. How can you make AWK understand as large integers as Python? ...

An integer is required? open()

I have a very simple python script that should scan a text file, which contains lines formatted as id='value' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code: import os,sys from os import * from sys import * vals = {} f = open(sys.argv[1], 'r') for line in val_f: t = li...