int

Data Validation for Random varying Phone Numbers

I am storing phone numbers of varying lengths in my WPF (C#, VS 08) App. I store them as strings. My question is about my method AddNewPhoneNo(string phoneNo). In this method, I use Int.TryParse to validate the incoming number (i.e. not null, is numeric...). I've since realized this is probably not the best way to do this, because then...

Java int concurrency ++int equivalent to AtomicInteger.incrementAndGet()?

Are these two equivalent? In other words, are the ++ and -- operators atomic? int i = 0; return ++i; AtomicInteger ai = new AtomicInteger(0); return ai.incrementAndGet(); ...

Is this technically thread safe despite being mutable?

Yes, the private member variable bar should be final right? But actually, in this instance, it is an atomic operation to simply read the value of an int. So is this technically thread safe? class Foo { private int bar; public Foo(int bar) { this.bar = bar; } public int getBar() { return bar; } } // ...

Python operators returning ints

Is there any way to have Python operators line "==" and ">" return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do...

Haskell : Type casting Int to String

I know you can convert a String to an number with read like so: Prelude> read "3" :: Int 3 Prelude> read "3" :: Double 3.0 But how do you grab the string representation of an Int value? ...

C# cast string to enum with enum attribute

Hello, i've got the following question: I've got public enum Als { [StringValue("Beantwoord")] Beantwoord = 0, [StringValue("Niet beantwoord")] NietBeantwoord = 1, [StringValue("Geselecteerd")] Geselecteerd = 2, [StringValue("Niet geselecteerd")] NietGeselecteerd = 3, } with public class Stri...

C int, float, double

There are certain int values that a float can not represent. However, can a double represent all values a float can represent? (My intuition says yes, since double has more fractional bits & more exponent bits, but there might be some silly gotchas that I'm missing). Thanks! ...

Am I writing this right? [noob]

private final int NUM_SOUND_FILES = 4; private Random rnd = new Random(4); private int mfile[] = new mfile[NUM_SOUND_FILES]; //the second mfile //reports error everytime mfile[0] = R.raw.sound1; mfile[1] = R.raw.sound2; mfile[2] = R.raw.sound3; mfile[3] = R.raw.sound4; int s...

Using an int as the numerical representation of a string in C#

I'm trying to use an integer as the numerical representation of a string, for example, storing "ABCD" as 0x41424344. However, when it comes to output, I've got to convert the integer back into 4 ASCII characters. Right now, I'm using bit shifts and masking, as follows: int value = 0x41424344; string s = new string ( new ...

In Java why would one intialise an int variable with 0 when it will be assigned 0 only by default when declared ?

What purpose does it serve ? Just read an example in a book where the author has done so. int numOfGuesses=0; ...

int datatype in 64bit JVM. Is it more "inefficient" than long?

I heard that using shorts on 32bit system is just more inefficient than using ints. Is this the same for ints on a 64bit system? Python recently(?) basically merged ints with long and has basically a single datatype long, right? If you are sure that your app. will only run on 64bit then, is it even conceivable (potentially a good idea...

Any significant performance improvement by using bitwise operators instead of plain int sums in C#?

Hello, I started working with C# a few weeks ago and I'm now in a situation where I need to build up a "bit set" flag to handle different cases in an algorithm. I have thus two options: enum RelativePositioning { LEFT = 0, RIGHT = 1, BOTTOM = 2, TOP = 3, FRONT = 4, BACK = 5 } ...

Java - Highest, Lowest and Average

Right, so why does Java come up with this error: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from double to int at rainfall.main(rainfall.java:38) From this: public class rainfall { /** * @param args */ public static void main(String[] args) { int[] numgroup; ...

Apparently it's important to use Int32 instead of int when messing with DLLImport stuff?

In C#, when messing with that system DLLImport/(unmanaged?) code stuff, I read somewhere it's important to use Int32 exact type instead of int. Is this true? And can someone please elaborate on why it's important to do this? ...

Convert System.Web.UI.WebControls.Unit to int in c#

How can I convert from an ASP.NET Unit structure to int in c#? Or reverse? ...

[Linq-To-Sql]How to return two values of different datatypes?

Here is my repository method which returns UserId , public IQueryable<int> getLoginStatus(string emailId, string password) { return (from r in taxidb.Registrations where (r.EmailId == emailId && r.Password == password) select r.UserId); } How to return UserName which is a string along with UserId... Any sugge...

how to work with other base numbers in java?

Guys if the int c=10001; which is a binary value.If i want to process it like multiplying it by 10 how to do that? ...

successor of int32 in C#

what is an immediate inheritor of int32 in C#? int or int16 ...

What is the most efficient way to truncate a number for a specific accuracy?

What is the most efficient way to truncate a number for a specific accuracy? ...

C# decimal places with integer operators

So I have this code: p.Value = 1; decimal avg = p.Value * 100 / 10000; string prntout = p.Key + " : " + avg.ToString(); Console.WriteLine(prntout); But the program prints out 0, instead of 0.01. p.Value is an int. How do I fix that? ...