integers

multiplication of large numbers, how to catch overflow

I am looking for an efficient (optionally standard, elegant and easy to implement) solution to multiply relatively large numbers,and store the result into one or several integers : Let say I have two 64 bits integers declared like this : uint64_t a = xxx, b = yyy; When I do a*b, how can I detect if the operation result in an overflow...

Calculations of ranges of numbers in PHP

Hi, and first of all, thank you for taking the time to read my question. I am trying to write a script, and I've come across an issue which I am finding hard to solve. I am working with a pair of numbers (for example, 1000 and 2000), and I have an array of pairs of numbers: $pairs = array( array(800, 1100), array(1500, 1600), ...

Python: List of lists of integers to absolute value to single number

If i had a list of list of integers say: [['12' '-4' '66' '0'], ['23' '4' '-5' '0'], ['23' '77' '89' '-1' '0']] I wanted to convert the numbers to their absolute values and then to a single number, so the output would be: 1246602345023778910 thanks ...

Fast multiplication of very large integers

How to multiply two very large numbers greater than 32 characters for example multiplication of 100! with 122! or 22^122 with 11^200 by the help of divide and conquer, do any body have java code or C# code? ...

floating and integers....?

why do we need integers and floating in processor?thank you ...

How does Python manage int and long?

Does anybody know how Python manage internally int and long types? Does it choose the right type dynamically? What is the limit for an int? I am using Python 2.6, Is is different with previous versions? How should I understand the code below? >>> print type(65535) <type 'int'> >>> print type(65536) <type 'int'> >>> print type(6553...

Setting ints to negative values using hexadecimal literals in C#

Is there any way to set an int to a negative value using a hexadecimal literal in C#? I checked the specification on Integer literals but it didn't mention anything. For example: int a = -1; // Allowed int b = 0xFFFFFFFF; // Not allowed? Hexadecimal notation is clearer for my application, and I'd prefer not to use uints becau...

How can I use arbitrary length integers in Perl?

Is there any standard way to use integers of arbitrary length in Perl? I am working on code that generates x64 assembly for tests, and I'm tired of manipulating 32 bits at a time. I'm using Perl 5.10.0, for what it's worth. ...

reading unknown number of integers from stdin (C)

I need to read an input file like : 1 19 20 41 23 2 41 52 43 3 90 91 941 4 512 5 6 51 61 each odd line is an integer each even line is unknown number of integers it is very easy in C++ while( cin >> k ){ ............ } Im not so used to C language so I couldnt make it in C. any ways to do it? ...

convert an integer to a string as3

How do I convert an integer to a string value? This must be easy. "Ya guys in SO are da best at explaining." I'm still working on these dumb counters. NEED TO JOIN THIS TOGETHER //My counter project "sends to dynamic text field" var timer:Timer = new Timer(10); var count:int = 0; //start at -1 if you want the first decimal to be 0 ...

print range of integers in descending or ascending order in java

I have an upper bound and a lower bound and I want to return all number number between the bounds including the bounds. I know python has a range function but I'm sure if java has this method. ...

How to use an int as an array of ints/bools?

I noticed while making a program that a lot of my int type variables never went above ten. I figure that because an int is 2 bytes at the shortest (1 if you count char), so I should be able to store 4 unsigned ints with a max value of 15 in a short int, and I know I can access each one individually using >> and <<: short unsigned int S...

A textbox class only accept integers in Java

I just want to do a textbox class only accepts integers.. I have done something, but ı think it's not enough. Can anyone help me, please? Thanks... import java.awt.TextField public class textbox extends TextField{ private int value; public textbox(){ super(); } public textbox(int value){ setDeger(val...

'long long int' is interpreted as 'long int'. How do I get round this?

I'm working on project involving c programming for my mathematics course at university. I need to be able to handle large integers, larger than those that can be stored in a 'long int' datatype. So I tried using 'long long int', but if I try something like this: long long int number; number = 10000000000; Then the error message says ...

Sending an int from Java to C using sockets

I was just wondering how to send an int from a Java application to a C application using sockets. I have got different C programs communicating with each other and have got the Java application retrieving data from the C application, but I can't work out sending. The C application is acting as database, the Java application then sends a...

How to define 2-bit numbers in C, if possible?

For my university process I'm simulating a process called random sequential adsorption. One of the things I have to do involves randomly depositing squares (which cannot overlap) onto a lattice until there is no more room left, repeating the process several times in order to find the average 'jamming' coverage %. Basically I'm performi...

Randomly generating sequence of ints in a specific range

Hi, I am unsure how to put this and my math skills aren't that strong. But here's what I need. I want to generate a list of all the 16bit integers (0-65535). But everytime I do so I want to seed the algorithm randomly that each time the list starts with a different integer and all the subsequent integers will be generated once but also ...

"hour" int taken from NSDate not behaving as expected at midnight??

I feel like I've lost my mind. Can someone tell me what's going on here? Also, I'm sure there is a better way to do what I'm trying to do, but I'm not interested in that now. I'd just like to solve the mystery of why my ints are not responding to logic as expected. // Set "At: " field close to current time NSDateFormatter *dateFormatter...

Integers not properly returned from a property list (plist) array in Objective-C

In summary, I am having a problem where I read what I expect to be an NSNumber from an NSArray contained in a property list and instead of getting a number such as '1', I get what looks to be a memory address (i.e. '61879840'). The numbers are clearly correct in the property list. Anyone know why this may be happening and what I can do ...

Which is faster in memory, ints or chars? And file-mapping or chunk reading?

Okay, so I've written a (rather unoptimized) program before to encode images to JPEGs, however, now I am working with MPEG-2 transport streams and the H.264 encoded video within them. Before I dive into programming all of this, I am curious what the fastest way to deal with the actual file is. Currently I am file-mapping the .mts file ...