integer

Fastest possible summing numbers up to N

Okay so i need really FAST algorithm or code in C if you have any it would be nice. The task is to sum all numbers from 1 to N for a given number N (it can be negative number too), so i did the usual way (you know just summing with loop from 1 to N) but it's not fast enough - i need something faster, i guess that i need the fastest possi...

[C++] Initializing Primitive Array to One Value

Is there a way to initialize an array of primitives, say a integer array, to 0? Without using a for loop? Looking for concise code that doesn't involve a for loop. :) ...

Why can't I enter an integer value into a decimal field?

I'm trying to write an insert statement for a SQL Server table that inserts the value 1 into a decimal field. The field is of the type decimal(10, 10) which, as far as I understand, means that it can have up to 10 digits altogether, and up to 10 of those digits can be after the decimal point. But, when I try to run the insert statement I...

Is There an Easy Way to Convert a Boolean to an Integer?

I am new to scala and I am finding the need to convert a boolean value to an integer. I know i can use something like if (x) 1 else 0 but I would like to know if there is a preferred method, or something built into the framework (ie toInt()) ...

Compare new Integer Objects in ArrayList Question

I am storing Integer objects representing an index of objects I want to track. Later in my code I want to check to see if a particular object's index corresponds to one of those Integers I stored earlier. I am doing this by creating an ArrayList and creating a new Integer from the index of a for loop: ArrayList<Integer> courseselectItem...

integer division properties

hi. does the following integer arithmetic property hold? (m/n)/l == m/(n*l) At first I thought I knew answer (does not hold), but now am not sure. Does it hold for all numbers or only for certain conditions, i.e. n > l? the question pertains to computer arithmetic, namely q = n/m, q*m != n, ignoring overflow. ...

Objective-C classes, pointers to primitive types, etc.

I'll cut a really long story short and give an example of my problem. Given a class that has a pointer to a primitive type as a property: @interface ClassOne : NSObject { int* aNumber } @property int* aNumber; The class is instantiated, and aNumber is allocated and assigned a value, accordingly: ClassOne* bob = [[ClassOne alloc] in...

How does the last integer promotion rule ever get applied in C?

6.3.1.8p1: Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands: If both operands have the same type, then no further conversion is needed. Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the typ...

Rationale in selecting Hash Key type

Guys, I have a data structure which has 25 distinct keys (integer) and a value. I have a list of these objects (say 50000) and I intend to use a hash table to store/retrieve them. I am planning to take one of these approaches. Create a integer hash from these 25 integer keys and store it on a hash table. (Yeah! I have some means to han...

Fastest way to calculate an X-bit bitmask?

I have been trying to solve this problem for a while, but couldn't with just integer arithmetic and bitwise operators. However, I think its possible and it should be fairly easy. What am I missing? The problem: to get an integer value of arbitrary length (this is not relevant to the problem) with it's X least significant bits sets to 1 ...

Does ( 0 < 0 ) return true?

ill have an if statement if (int1 < int2) {} else {} I want the else statement to run if both int1 and int2 are 0.. ...

Given an array of integers [x0 x1 x2], how do you calculate all possible permutations from [0 0 0] to [x0 x1 x2]?

I am writing a program that takes in an ArrayList and I need to calculate all possible permutations starting with a list of zeroes, up to the value in the corresponding input list. Does anyone know how to iteratively calculate these values? For example, given [ 1 2 ] as input, it should find and store the following lists: [0 0], [1 0]...

Unusual conversion error (string to integer) asp.net

I have my repeater item template: <asp:Repeater ID="Linksrepeater" runat="server"> <HeaderTemplate><h2>Links</h2><ul> </HeaderTemplate> <ItemTemplate> <li><%#Container.DataItem("Category")%></li> </ItemTemplate> <FooterTemplate> </ul> </FooterTemplate> </asp:Repeater> Hooked up to: s = "sql" x = New SqlCommand(s, c) ...

How to concatenate int values in java?

hi, I have the following values: int a=1; int b=0; int c=2; int d=2; int e=1; How do i concatenate these values so that i end up with a String that is 10221; please note that multiplying a by 10000, b by 1000.....and e by 1 will not working since b=0 and therefore i will lose it when i add the values up. Thnks you in advance. ...

given a list of up to 10 integer numbers and a sum, will display a subset of the numbers whose total is that sum

Write a program which, given a list of up to 10 integer numbers and a sum, will display a subset of the numbers whose total is that sum if one exists or indicate that none exists otherwise. For example, for the list: 5,13,24,9,3,3 and sum = 28, your program should display 13, 9, 3, 3. How to do this in C++ using a recursive function? ...

How to convert an 8-bit integer into a binary string in xquery?

At work today, we threw together this attempt: xquery version "1.0"; declare option saxon:output "omit-xml-declaration=yes"; declare variable $x := 99; string-join( for $b in (128,64,32,16,8,4,2,1) let $xm := $x mod ($b*2) return if ( $xm >= $b ) then "1" else "0" , "") Do you have a better way? Takin...

Python hash() can't handle long integer?

I defined a class: class A: ''' hash test class >>> a = A(9, 1196833379, 1, 1773396906) >>> hash(a) -340004569 This is weird, 12544897317L expected. ''' def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d def __hash__(self): return self.a ...

Convert a list of strings [ '3', '1' , '2'] to a list of sorted integers [ 1, 2, 3]

I have: L1 = ['11', '10', '13', '12', '15', '14', '1', '3', '2', '5', '4', '7', '6', '9', '8'] this is a list of strings, right? I need to make it a list of integers as follows: L2 = [11, 10, 13, 12, 15, 14, 1, 3, 2, 5, 4, 7, 6, 9, 8] finally I will sort it like below: L3 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] by L2.sort() please let ...

Number query in sql

I have table in sql as User | Account -----+--------- 1 | 25 1 | 31 1 | 35 1 | 44 1 | 50 1 | 59 and output need in as three columns 1 | 25 | 31 1 | 35 | 44 1 | 50 | 59 ...

Converting a string to an integer (Android)

I'm not 100% on how to do this so i'm asking... May seem stupid but... How do I convert a string into an integer? Background info: I have a textbox I have the user enter a number into... it then: EditText et = (EditText) findViewById(R.id.entry1); String hello = et.getText().toString(); gets the string 'hello' Now I wan...