int

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...

Appending ints to char* and then clearing

I'm working on a project using an Arduino and as such, I'm reading from a serial port (which sends ints). I need to then write this serial communication to an LCD, which takes a char*. I need to read several characters from the serial port (2 integers) into a string. After both have been received, I then need to clear the string to prep...

.Net Simple RSA encryption

Hi, I'm trying to encrypt something simple, like int or long. Simplest way I found looks like: int num = 2; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] numBytes = BitConverter.GetBytes(num); byte[] encryptedBytes = rsa.Encrypt(numBytes, true); Problem is, the encryptedBytes is 128 bytes long. How can I encry...

How to use long id in Rails applications?

How can I change the (default) type for ActiveRecord's IDs? int is not long enough, I would prefer long. I was surprised that there is no :long for the migrations - does one just use some decimal? ...

Ruby round float to_int if whole number

In ruby, I want to convert a float to an int if it's a whole number. For example a = 1.0 b = 2.5 a.to_int_if_whole # => 1 b.to_int_if_whole # => 2.5 Basically I'm trying to avoid displaying ".0" on any number that doesn't have a decimal. I'm looking for an elegant (or built-in) way to do def to_int_if_whole(float) (float % 1 ==...

SQL Server GUID (from Active Directory) vs Int

We migrated a lot of data from our old ordering system. This system stored the users initials in our "Orders" table for each order they created. Now that we have a view that looks at active directory I would like to update those initials with the active directory objectguid (or something that references the guid). This would allow us to ...

Why can't I unbox an int as a decimal?

I have an IDataRecord reader that I'm retrieving a decimal from as follows: decimal d = (decimal)reader[0]; For some reason this throws an invalid cast exception saying that the "Specified cast is not valid." When I do reader[0].GetType() it tells me that it is an Int32. As far as I know, this shouldn't be a problem.... I've tested ...

How to create FILETIME in Win32?

I have a value __int64 that is a 64bit FILETIME value. FILETIME has a dwLowDateTime and dwHighDateTime. When I try to assign a __int64 to a FLIETIME I get a C2440. How do I assign the __int64 to the FILETIME? Or how do I split the __int64 so that I can assign the low part to dwLowDateTime and the high part to dwHighDateTime? Thanks! ...

How to convert from int to string in objective c: example code...

I am trying to convert from an int to a string but I am having trouble. I followed the execution through the debugger and the string 'myT' gets the value of 'sum' but the 'if' statement does not work correctly if the 'sum' is 10,11,12. Should I not be using a primitive int type to store the number? Also, both methods I tried (see comm...

Why doesn't this overflow?

Given this code: int x = 20000; int y = 20000; int z = 40000; // Why is it printing WTF? Isn't 40,000 > 32,767? if ((x + y) == z) Console.WriteLine("WTF?"); And knowing an int can hold −32,768 to +32,767. Why doesn't this cause an overflow? ...

increment int object

Is there a way in python to increment int object in place, int doesn't seem to implement __iadd__ so += 1 actually returns a new object >>> n=1 >>> id(n) 9788024 >>> n+=1 >>> id(n) 9788012 What I want is n to remain pointing to same object. Purpose: I have class derived from int and I want to implement C type '++n' operator for that ...

C/C++ an int value that isn't a number ?!

Can this ever happen ? 3 asserts, where one should activate. int nr = perform_calc(); assert( nr == 0); assert( nr > 0); assert( nr < 0); Can there be a case when the program doesn't activate the asserts on g++ 3.4.4. And no I don't have the possibility to change the code in order to print the number out in case the asserts don't act...

Fastest/easiest way to average ARGB color ints?

I have five colors stored in the format #AARRGGBB as unsigned ints, and I need to take the average of all five. Obviously I can't simply divide each int by five and just add them, and the only way I thought of so far is to bitmask them, do each channel separately, and then OR them together again. Is there a clever or concise way of av...

read a int from a file wrote by java's writeInt method in C++?

How would one go about doing this? Also, is there an easy way to do it? Using a lib like Boost or something? ...

string::size_type instead of int

const std::string::size_type cols = greeting.size() + pad * 2 + 2; Why string::size_type? int is supposed to work! it holds numbers!!! ...

C - Check if Integer is assigned

Hi, How do I determine if an integer is unassigned? int i; /* no assignment */ if (/* conditional statement here to check if int i is unassigned or not */) { printf("Integer is unassigned!\n"); } else { printf("Integer is assigned!\n"); } Language: C Best regards, Timothy ...

string to integer in xslt

Hi i want to conver a string value in xslt to a integer value.I am using xslt 1.0 so i can't use those functions supported in xslt 2.0 . Please help . ...

What is are differences between Int and Integer in Scala?

I was working with a variable that I had declared as an Integer and discovered that > is not a member of Integer. Here's a simple example: scala> i warning: there were deprecation warnings; re-run with -deprecation for details res28: Integer = 3 scala> i > 3 <console>:6: error: value > is not a member of Integer i > 3 ^...

How to convert float to int with Java

I used the following line to convert float to int, but not as accurate as I'd like : float a=8.61f; int b; b=(int)a; The result is : 8 [ It should be 9 ] When a=-7.65f, the result is : -7 [ It should be -8 ] What's the best way to do it ? ...

How do I convert from int to long in Java?

I keep finding both on here and Google people having troubles going from long to int and not the other way around. Yet I'm sure I'm not the only one that has run into this scenario before going from int to Long. The only other answers I've found were "Just set it as Long in the first place" which really doesn't address the question. Ca...