integer

Convert int to CGFloat

Any idea on how to convert int to CGFloat in objective C? ...

C++ convert hex string to signed integer

I want to convert a hex string to a 32 bit signed integer in C++. So, for example, I have the hex string "fffefffe". The binary representation of this is 11111111111111101111111111111110. The signed integer representation of this is: -65538. How do I do this conversion in C++? This also needs to work for non-negative numbers. F...

How do I avoid compiler warnings when converting enum values to integer ones?

I created a class CMyClass whose CTor takes a UCHAR as argument. That argument can have the values of various enums (all guaranteed to fit into a UCHAR). I need to convert these values to UCHAR because of a library function demanding its parameter as that type. I have to create a lot of those message objects and to save typing effort I ...

Why does Integer.TryParse set result to zero on failure?

My understanding of the Integer.TryParse() function was that it tried to parse an integer from the passed in string and if the parse failed the result integer would remain as it did before. I have an integer with a default value of -1 which I would like to remain at -1 if the parse fails. However the Integer.TryParse() function on faili...

Is there a relation between integer and register sizes?

Recently, I was challenged in a recent interview with a string manipulation problem and asked to optimize for performance. I had to use an iterator to move back and forth between TCHAR characters (with UNICODE support - 2bytes each). Not really thinking of the array length, I made a curial mistake with not using size_t but an int to it...

Signed 64 by 32 integer division

Assuming you have a machine instruction udive that does a special case 64 by 32 unsigned division by taking a (32bit dividend << 32) / 32bit divisor, we can do a full 64 by 32 division using the following: // assume: a / b guaranteed not to overflow a = 64bit dividend, a.h & a.l are hi & lo 32bits respectively b = 32bit divisor q1 = ud...

Convert a string to integer with decimal in Python

I have a string in the format: 'nn.nnnnn' in Python, and I'd like to convert it to an integer. Direct conversion fails: >>> s = '23.45678' >>> i = int(s) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '23.45678' I can convert it to a decimal by using: >>> ...

Java: Implementing a Unsigned 128bit Integer

** first off I should ask: ** Does anyone knows of a current implementation 126b UINT for Java ? I need something to hold natural cardinal values. ie: A huge counter. I know of BigIntegers, which are slow and immutable. A 128b UINT makes sense ... I was think about implementing an OWORD, using a pair of primitive longs. Overflows wou...

Image shaking when StretchDIBits partially.

I am using C++ GDI, StretchDIBits to draw images on DC. Because the original Image is large, and high quality is needed. I use HAFTONE mode, to draw whole image on DC(zoom the image) seems time comsuming. So I decide to draw partially using StretchDIBits. But there is a serious problem about StretchDIBits. I can only draw rect in int...

iPhone sdk: I'm trying to increase an integer by 10 and failing

(Problem solved now, see answers below) Hello, in my app I am trying to create a points counter. That increases a number by 10 every time a button is pressed. I successfully managed to get my app to increase a value (0) by 1 every time a button is pressed, and to remember the latest value and display it next time the app starts. But w...

How do I Convert a String into an Integer in JavaScript?

How do I convert a string into an integer in JavaScript? Is it possible to do this automatically, or do I have to write a subroutine to do it manually? ...

Convert an integer to a byte[] of specific length

I'm trying to create a function (C#) that will take 2 integers (a value to become a byte[], a value to set the length of the array to) and return a byte[] representing the value. Right now, I have a function which only returns byte[]s of a length of 4 (I'm presuming 32-bit). For instance, something like InttoByteArray(0x01, 2) should r...

getc(stdin) reads keyboard input to integers, but what if I want to read keyboard input to character strings? (C++) Thanks

#include "stdafx.h" #include "string.h" #include "stdio.h" void CharReadWrite(FILE *fin); FILE *fptr2; int _tmain(int argc, _TCHAR* argv[]) { char alpha= getc(stdin); char filename=alpha; if (fopen_s( &fptr2, filename, "r" ) != 0 ) printf( "File stream %s was not opened\n", filename ); else printf( "The fi...

Inconsistent behavior on java's ==

Consider this code: class test { public static void main(String[] args) { test inst_test = new test(); int i1 = 2000; int i2 = 2000; int i3 = 2; int i4 = 2; Integer Ithree = new Integer(2); // 1 Integer Ifour = new Integer(2); // 2 System.out.println( Ithree == Ifour ); inst_test....

Does NSNumber add any extra bytes to the number it holds?

I'm working with Objective-C and I need to add int's from a NSArray to a NSMutableData (I'm preparing a to send the data over a connection). If I wrap the int's with NSNumber and then add them to NSMutableData, how would I find out how many bytes are in the NSNumber int? Would it be possible to use sizeof() since according to the apple d...

reading integers from binary file in python

Hi there... I don't know if the question title is correctly set. I'm trying to read a BMP file in python. I know the first two bytes indicate the bmp firm. Next 4 bytes are the file size. When I excecute: fin = open("hi.bmp", "rb") firm = fin.read(2) file_size = int(fin.read(4)) I get ValueError: invalid literal for int() wit...

Trying to grab integer from pre-defined p-list? ObjC/Cocoa

Hello, I'm working on an Objective-C/Cocoa roguelike, because I've always found that working on a game is the best way to learn about a language. I've gotten quite far with my game, but I'm having a problem. Each level.plist is defined with a few things, like so: <key>Save Location</key> <integer>0</integer> It's grabbed like so, I'...

How do I factor integers using Perl?

I want split integers into their factors. For example, if the total number of records is: 169 - ( 13 x 13 times) 146 - ( 73 x 2 times) 150 - ( 50 x 3 times) 175 - ( 25 x 7 times) 168 - ( 84 x 2 ) 160 - ( 80 x 2 times) When it's more than 10k - I want everything on 1000 When it's more than 100k - I want everything on 10k In this w...

What is the maximum integer value in Flex?

I was trying to display a number: 2893604342.00. But, when i am displaying it it is displayed as: -2893604342. Following is the code snippet ... avg += int(totalData[i][col.dataField]); I have even replaced it with Number, but it's still showing the same negative number. Please let me know whether there is any problem with int or Nu...

Arrays.asList() of an array

Hi! My question is: what is wrong with this conversion? public int getTheNumber(int[] factors) { ArrayList<Integer> f = new ArrayList(Arrays.asList(factors)); Collections.sort(f); return f.get(0)*f.get(f.size()-1); } I made this after reading solution found in http://stackoverflow.com/questions/157944/how-to-create-array...