integer

How do I convert hex string into signed integer?

I'm getting a hex string that needs to be converted to a signed 8-bit integer. Currently I'm converting using Int16/Int32, which will obviously not give me a negative value for an 8-bit integer. If I get the value 255 in Hex, how do I convert that to -1 in decimal? I assume I want to use an sbyte, but I'm not sure how to get that valu...

NSString to 64bit integer converstion on iPhone

Hi! I am struggling with very simple thing: I receive some ids by http request as a string. I know they represent 64bit integer id numbers. How can I convert them to the 64 bit Integers (NSNumber or NSInteger)? Functions like: [nsstring integerValue], [nsstring intValue] seems to be 32bit limited (max value:2147483647). Any Hints? ...

storing Integer objects with primitive int in HashMpa

Hi, HashMap uses objects as a key. If you use int primitive as key, it uses auto boxing and create integer objects for key. is there any hashmap implementation uses primitive types as key. I dont want autoboxing. becuase hascode of integer is also value of integer. I am trying to create integer object pool. regards Trustin ...

how to extract 64 bit signed integer value

I'm querying a NSDictionary for a value. Because I got problems I printed the object. It shows me the following: <CFString 0x5d33630 [0x26af380]>{contents = "myDictionaryItem"} = <CFNumber 0x5d58940 [0x26af380]>{value = +1286301600, type = kCFNumberSInt64Type} So it is of type signed 64 bit integer. So I tried to extract the value like...

C++ 2.5 bytes (20-bit) integer

I know it's ridiculous but I need it for storage optimization. Is there any good way to implement it in C++ ? It has to be flexible enough so that I can use as normal data type e.g Vector< int20 >, operator overloading etc.. ...

Best way to convert an array of integers to a string in Java

In Java, I have an array of integers. Is there a quick way to convert them to a string? I.E. int[] x = new int[] {3,4,5} x toString() should yield "345" ...

Integer to CGFloat help needed.

In my iPhone app, I have a appSettings.plist. This allows me, but also others to simply change some parameters. One of the parameters is the predominant color of the app. The .plist looks like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd...

how to convert -1 to 1 with javascript ?

how to convert -1 to 1 with javascript ? var count = -1; //or any other number -2 -3 -4 -5 ... or var count = 1; //or any other number 2 3 4 5 ... result should be var count = 1; //or any other number 2 3 4 5 ... ...

Ruby: Best way to convert a String to Integer or leave it as String if necessary?

Developing a little survey webapp, ran into problem that deals with ranges for rating type questions. So a rating's range could be: 1..10 -5..0 -5..5 'a'..'z' 'E'..'M' and so on The range is stored as a pair of varchars in database (start and end of range). So range always starts off as a string input. What is the best way to take t...

Filtering out highest integer from an array of links

But of a confusing title so let me explain. I have an array of links like this: http://somesite.com/videoplayback?ip=81.0.0.0&amp;sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&amp;fexp=905602&amp;algorithm=throttle-factor&amp;itag=34&amp;ipbits=8&amp;burst=40&amp;sver=3&amp;expire=1285056000&amp;key=yt1&amp;signature=690F9475D...

Format integer to 2 places.

Hello, I'm trying to format integer to 2 characters, i.e. 01, 02, 03 instead of 1, 2, 3, 4. I've done a few google searches but could not find anything. Can @"%d" be changed to reflect 2 characters ? timeArray = [[NSMutableArray alloc] init]; for (int i = 0; i < 25; i++){ NSString *timeValue = [NSString stringWithFormat:@"%d", i]; ...

Why is an int in OCaml only 31 bits?

Haven't seen this "feature" anywhere else. I know that the 32nd bit is used for garbage collection. But why is it that way only for ints and not for the other basic types? ...

Ruby Hash bug help!

I'm trying to create a Ruby Hash of objects, where the keys are the object @name member: # m is an object with an @name instance variable (a string) myHash = {} myHash[m.name] = m It's giving this error: #<TypeError: can't convert String into Integer> Anyone know why? I'm sure that m.name is a valid string... ...

Getting error when added NSNumber to an array

When my program gets to the line: [userNumSequence addObject:[NSNumber numberWithInteger: sequenceNumber]]; it gets the error: Program received signal: “EXC_BAD_ACCESS”. All I'm wanting to do is to store an integer in the array. // JBNumberGeneration.m #import "JBNumberGeneration.h" @implementation JBNumberGeneration - (id) init...

C++ strange output converting string to int

I'm writing a program that converts a binary string to decimal. I wanted to validate my output before I get really started on this method. I have the following code: int get_val() { int sum =0; for(int num_bits = size; num_bits>0; num_bits--) { printf("String sub %i is %i\n", num_bits, int(bin[num...

C++: Store large numbers in a float like PHP?

In PHP if you go above INT_MAX it will cast it as a float, allowing very high numbers to be formed (that are non-decimal as well), is this possible to do in C++ or are the way they store floating point/double precision numbers different? The reason why is I am wishing to benchmark large factorials, but something such as 80! is way too l...

Integer time complexity in Haskell

Hello! I had an assignment in school last week to implement a function for calculating the n:th number in the fibonacci sequence. A 'sub-assignment' was to implement it using accumulation(Might not be a correct translation) in order to give the function O(n) time complexity. This all worked fine until I tried making the function (Int ->...

Java reverse int value

Can anyone explain to me how to reverse an integer without using array or String. I got this code from online, but not really understand why + input % 10 and divide again. while (input != 0) { reversedNum = reversedNum * 10 + input % 10; input = input / 10; } ...

Integer convert to WoW Gold

Heya all, For a MMORPG World of Warcraft im trying to write a lib. Money in that games is stored as an Integer and in game currency is not an integer it's based of Gold, Silver and Copper coins. Every 100 copper is 1 silver and every 100 silver is 1 gold. Now I need to convert such an integer to the WoW Money format: for example 1231...

Is there a standard Cyclic Integer Class in C++?

I have a problem that is quite common in the code that I am writing at the moment whereby I want to have an integer that can only exist inside a certain range where the range is [start, end). Basically I want to be able to do something like the following: cyclic_int ci(4, 8); ci = 4; assert(ci == 4); ci += 3; assert(ci == 7); ci += 2; ...