integer

What happens if I assign a negative value to an unsigned variable?

I was curious to know what would happen if I assign a negative value to an unsigned variable. The code will look somewhat like this. unsigned int nVal = 0; nVal = -5; It didn't give me any compiler error. When I ran the program the nVal was assigned a strange value! Could it be that some 2's complement value gets assigned to nVal? ...

how to convert byte value into int in objective-c

Hello, Please tell me how to convert bytes to NSInteger/int in objective-c in iPhone programming? ...

Java Integer: what is faster comparison or subtraction?

I've found that java.lang.Integer implementation of compareTo method looks as follows: public int compareTo(Integer anotherInteger) { int thisVal = this.value; int anotherVal = anotherInteger.value; return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1)); } The question is why use comparison instead of subtraction: return th...

C++ Thread Safe Integer

Hello everyone, I have currently created a C++ class for a thread safe integer which simply stores an integer privately and has public get a set functions which use a boost::mutex to ensure that only one change at a time can be applied to the integer. Is this the most efficient way to do it, I have been informed that mutexes are quite ...

How to turn character date into integer JavaScript

I need a way to turn my 2 character string dates (i.e. '04/10/2010' & '05/24/2010') into an integers to see if one is greater than the other. If the user enters an end date that is less than the begin date I need to popup an "invalid date range" error. ...

unsigned tinyint in php?

I'm working on a class to manipulate html hex color codes in php. Internally, the class treats RGB values as decimals. When I'm adding or subtracting, I never want the value to exceed 255 nor 'subceed' zero. If course, I can do something piecemeal like if ( $val > 255 ) { $val = 255; } if ( $val < 0 ) { $val = 0; } But th...

C - Convert long int to signed hex string

MASSIVE EDIT: I have a long int variable that I need to convert to a signed 24bit hexadecimal string without the "0x" at the start. The string must be 6 characters followed by a string terminator '\0', so leading zeros need to be added. Examples: [-1 -> FFFFFF] --- [1 -> 000001] --- [71 -> 000047] Answer This seems to do the trick: ...

How to find multiples of the same integer in an arraylist?

Hi My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i'm unsure how to count how many of each of the values exist. The problem is how to find the duplicate values in the arraylist and count how many of that par...

How to detect padding on an integer and treat it as a string?

I have this function to prepare variable to be used in a SQL query: function sqlize($mInput) { if (!isset($mInput)) $mInput = "null"; elseif (strtolower($mInput) == "null") { } elseif (is_numeric($mInput)) { } elseif (is_string($mInput)) { $mInput = trim($mInput); $mInput = addslashes($mInp...

Is there really such a thing as a char or short in modern programming?

Howdy all, I've been learning to program for a Mac over the past few months (I have experience in other languages). Obviously that has meant learning the Objective C language and thus the plainer C it is predicated on. So I have stumbles on this quote, which refers to the C/C++ language in general, not just the Mac platform. With C ...

Question about C behaviour for unsigned integer underflow

I have read in many places that integer overflow is well-defined in C unlike the signed counterpart. Is underflow the same? For example: unsigned int x = -1; // Does x == UINT_MAX? Thanks. I can't recall where, but i read somewhere that arithmetic on unsigned integral types is modular, so if that were the case then -1 == UINT_MAX m...

Syntax error converting the nvarchar value to a column of data type int.

I have 1,2,3,4,5,6,7,8,9 stored as nvarchar inside Level in my db. I then have a dropdownlist with values 1,2,3,4,5,6,7,8,9. When a user makes a selection (i.e 1) (Level.SelectedValue.ToString). This builds an sql query via a param like this: "Select things From MBA_EOI Where level = 1" When I run the select I get the following erro...

PHP: Is_numeric returns false on 0

Hi everyone, Is_numeric() as well as is_int() returns false if the value is 0. What can i do instead to verify that a specific value is numbers only in PHP? Are we heading straight for the Regular Expressions camp, or are there some nice, handy feature for this out there already? Thanks! ...

Python TypeError: an integer is required

import scipy,array def try_read_file(): def line_reader(lines): for l in lines: i = l.find('#') if i != -1: l = l[:i] l = l.strip() if l: yield l def column_counter(): inputer = (line.split() for line in line_reader(file('/home/kartik/Downloads/yahoo_dataset/set1...

Allow number to start with ZERO when stored in mysql integer field

I need to store phone numbers starting with 0 but whenever i try to store this in MySql table the starting ZERO is removed because no number start with Zero actually how i can solve this problem please do i need to change the field type from Integer to another type please help ...

Int arrays in Objective-C

So I have this: int a[4] = { 0, 1, 2, 3 }; And then I want to make a new int array: int b[4]; What is the easiest way to make b[] = a[]? ...

Addition of an integer to a pointer

In following code, #include<stdio.h> int main() { short a[2]={5,10}; short *p=&a[1]; short *dp=&p; printf("%p\n",p); printf("%p\n",p+1); printf("%p\n",dp); printf("%p\n",dp+1); } Now the output I got was : 0xbfb45e0a 0xbfb45e0c 0xbfb45e04 0xbfb45e06 Here I understood p and p+1, but when we do dp...

Number representation problem in php

Hi everybody, It is a simple thing but i don't get answer for that. I am generated auto generation id concatenate with year 100001, 100002 like that, in this 10 is year 0001 is auto generation numbers. When i split the year and number then getting add one value is 2 for 0001. but i need as 0002. Adding value is 0001+1, 0002+1, 0010+...

casting doubles to integers in order to gain speed

Hello all, in Redis (http://code.google.com/p/redis) there are scores associated to elements, in order to take this elements sorted. This scores are doubles, even if many users actually sort by integers (for instance unix times). When the database is saved we need to write this doubles ok disk. This is what is used currently: snprin...

Making a string out of a string and an integer in Python

I get this error when trying to take an integer and prepend "b" to it, converting it into a string: File "program.py", line 19, in getname name = "b" + num TypeError: Can't convert 'int' object to str implicitly That's related to this function: num = random.randint(1,25) name = "b" + num ...