integer

Mapping Two Continuous Sorted Integer Sets onto One Integer Set

I have an algorithms problem you should help me out with: I am trying to map two continuous sorted integer sets (with potentially differing number of items) to a single continuous sorted integer set preserving linear spacing. e.g. A: {1,2,3} B: {1,2,3,4} could map onto C: {1,2,3,4,5,6,7} by A: {1->1, 2->4, 3->7} and B: {1->1, 2->3, 3->5...

Android: How to read a number as int from a String; basically to read Text of a ListViewItem?

Hi, This is my problem. I have a ListView, each row is a CheckedTextView. The list view items are "1", "2" and "3". When a ListItem is clicked, I want to read the number and assign it to an int variable. I did the following to read the Text of the clicked item: onItemClick(AdapterView<?> parent, View v, int position, long id) { ...

find if an integer exists in a list of integers

i have this code: List<T> apps = getApps(); List<int> ids; List<SelectListItem> dropdown = apps.ConvertAll(c => new SelectListItem { Selected = ids.Contains(c.Id), Text = c.Name, Value = c.Id.ToString() }).ToList(); ids.Contains seems to always return false even...

Inserting a number as a String into a Text column and SQLite stills removes the leading zero

Hi, I got the following number as a string: String numberString = "079674839"; When I insert this number into a SQLite DB, SQLite automatically removes the leading zero and stores the string as 79674839. Considering affinity and that the column stores TEXT, shouldn't SQLite store the whole string and keep the leading zero? Thanks ...

How do I determine the number of bits in a template non-type integral constant parameter?

I would assume that this is covered in the C++ Standard, but I've not been able to find it. I am writing some templates that are going to do arithmetic on their non-type integral parameters, and I find I need the equivalent of MAX_INT for the parameter 'x' in a template like template <int x> Foo. Ideally someone could point me to the pa...

Rotating bits of any integer in C

Pass a integer 2 to this function and then return a integer which is 4 x = 2; x = rotateInt('L', x, 1); (left shift the bits by 1) Example: 00000010 -> rotate left by 1 -> 00000100 but if I pass this: x = rotateInt('R', x, 3); it will return 64, 01000000 Here is the code, can someone correct the error... thanks int rotateInt...

Choosing the most suitable integer size/range to use for variables

stdint.h in C99 provides many options for integer sizes, types and ranges - so many I don't know what ones to choose! I know how to use size_t and ptrdiff_t when appropriate, and I use fixed size types for storage and transmission. My question concerns values that will only be stored in memory of the host machine. For example, a struct...

extending java Integer cahce

Why YOU should use Integer.valueOf(int) In particular, why you should use Integer.valueOf(int) instead of new Integer(int): CACHING. But in JDK 5+, you should really use valueOf because Integer now caches Integer objects between -128 and 127 and can hand you back the same exact Integer(0) object every time instead of wasting an object...

More about rotateLeft method in java

please tell me examples of [rotateLeft][1] method of Integer class in java [1]: http://download-llnw.oracle.com/javase/6/docs/api/java/lang/Integer.html#rotateLeft(int, int) ...

Casting an int to a string in Python

I want to be able to generate a number of text files with the names fileX.txt where X is some integer: for i in range(key): filename = "ME" + i + ".txt" //Error here! Can't concat a string and int filenum = filename filenum = open(filename , 'w') Does anyone else know how to do the filename = "ME" + i part so I get a li...

What's the "java" way of converting chars (digits) to ints

Given the following code: char x = '5'; int a0 = x - '0'; // 0 int a1 = Integer.parseInt(x + ""); // 1 int a2 = Integer.parseInt(Character.toString(x)); // 2 int a3 = Character.digit(x, 10); // 3 int a4 = Character.getNumericValue(x); // 4 System.out.printf("%d %d %d %d %d", a0, a1, a2, a3, a4); (version 4 ...

Is there any way to compute the width of an integer type at compile-time?

The size of an integer type (or any type) in units of char/bytes is easily computed as sizeof(type). A common idiom is to multiply by CHAR_BIT to find the number of bits occupied by the type, but on implementations with padding bits, this will not be equal to the width in value bits. Worse yet, code like: x>>CHAR_BIT*sizeof(type)-1 ma...

FileSize Problem - Cocoa

Hello, I've written methods that help me get the size of files/folders and translate the result in a human readable string. Problem is, when this size exceeds about 2.1GB, the number returned changes to a random negative number, like "-4324234423 bytes", which is useless. Things I've found out about & done about this issue: 32GB is l...

Kinds of integer overflow on subtraction

I'm making an attempt to learn C++ over again, using Sams Teach Yourself C++ in 21 Days (6th ed.). I'm trying to work through it very thoroughly, making sure I understand each chapter (although I'm acquainted with C-syntax languages already). Near the start of chapter 5 (Listing 5.2), a point is made about unsigned integer overflow. Bas...

how to get length of integers in PHP ?

hello everyone, I want to get the length of integer values for validation in PHP. Example: Mobile numbers should be only 10 integer values. It should not be more than 10 or less than 10 and also it should not be included of alphabetic characters. How can i validate this. Sorry for my poor English. Thanks In Advance ...

Integer to Binary Erlang

Hi, I am trying to make an integer into a binary: 543 = <<"543">> How can I do this without integer_to_list(list_to_binary(K)). ...

Conversion of 32-bit Hex to integer

Hi, I want to convert 32-bit Hex to integer in 'C' seqBuf = "81BD82E8" This is the Hex value I'm getting and stored in a buffer The corresponding value of that hex value is 2176680680 How to convert? Please help me.... Is there any function "strtoull()" as like strtoul()... Thanks in advance... ...

Struts 2 List Parameter Passing

How do I pass a list of integers using the s:a href and param tags in Struts 2? Example POJO: private List<Integer> myList = new ArrayList<Integer>(); public List<Integer> getMyList() { return myList; } public void setMyList(List<Integer> myList) { this.myList = myList; } Example JSP Page: <s:url id="testUrl" action="testA...

Converting BigDecimal to Integer

Hi, I have Hibernate method which returns me a BigDecimal. I have another API method to which I need to pass that number but it accepts Integer as parameter. I cannot change return types or variable types of both methods. Now how to convert the BigDecimal into Integer and pass it to second method? Is there a way out of this? ...

Objective-C problems performing math on an integer

I have the following line of code which is running on a timer: NSLog( @" seconds: %i, elapsedhours %f", [self elapsedSeconds], [self elapsedSeconds] / 3600); It prints out: seconds: 0, elapsedhours 0.000000 seconds: 1, elapsedhours 0.000000 seconds: 2, elapsedhours 0.000000 seconds: 3, elapsedhours 0.000000 I'm wondering why elapse...