Questions tagged [integer]

Use this tag for questions about using, storing or manipulating integral values of all types and sizes, including concerns about overflow. Not for code that casually happens to use integers.

Filter by
Sorted by
Tagged with
5
votes
3answers
18k views

Split a long integer into eight 4-bit values

It's an exercise from a book. There is a given long integer that I should convert into 8 4-bit values. The exercise is not very clear for me, but I think I understood the task correctly. I googled ...
4
votes
4answers
11k views

Integer-to-hex string generator

I am using this as a learning exercise primarily and want to ensure my code is optimal. The main thing is that it is reliable and I am made aware of any flaws. Could it be made more efficient or ...
4
votes
1answer
741 views

What do you think about this uint64 random generator?

I've looked for a good method to generate an integer inside a range of values. I think using modulo is not a good method because the values are not perfectly mapped in the range. So I mapped the ...
2
votes
2answers
187 views

Float string to integer string

I have a float in the String strFloat. I wanted to convert it to a rounded integer also stored in a ...
4
votes
2answers
2k views

Long-to-string and string-to-long while checking characters within a xlate table

I am attempting to come up with a better method for doing this: ...
7
votes
3answers
16k views

Separate numbers with commas

How should I approach refactoring this code? ...
5
votes
3answers
4k views

Decimal/binary/hex converter

I've finally finished my converter and have determined that it works, but I'm trying to make it cleaner and/or more practical (primarily with the switch statements)....
5
votes
3answers
896 views

Haskell functions to extract and reverse integers hiding in strings

There may not be a "right" way to do it, but I'm inexperienced in functional programming. I'd like some feedback on how the code can be written in a more idiomatic way. Here it is: ...
7
votes
2answers
8k views

Determine if an int is within range

Can I somehow make this a bit cleaner using Math.[Something], without making a method for it? ...
0
votes
2answers
2k views

Spotify's “Reversed Binary Numbers” Problem [closed]

I wrote some Java code for Spotify's Reversed Binary Numbers puzzle and I tested it on my machine and I am almost positive that it behaves as expected. However, when I send it to puzzle AT spotify.com ...
1
vote
1answer
230 views

How to improve this functional python trial division routine?

The following functional program factors an integer by trial division. I am not interested in improving the efficiency (but not in decreasing it either), I am interested how it can be made better or ...
9
votes
4answers
14k views

BigInteger implementation in C, supporting addition and multiplication

I've implemented adding and multiplying arbitrary precision integers. Also available as a gist. ...
2
votes
2answers
420 views

NSArray and NSNumber-int conversions

I have a textView which is displaying a string. I also have an array which keeps track of where every line begins, it stores the "start index" or NSRange.location for every line. However, when text ...
9
votes
2answers
20k views

Effectively convert little endian byte slice to int32

I have a data stream of bytes and I'd like to get a little endian encoded int32 from four bytes. Is there a better way than to do this like the following code? ...
2
votes
1answer
5k views

Get int array from database Cursor

I find this code quite ugly, but in fact, I can't find a finer way of achieving the goal. ...
5
votes
2answers
979 views

Improving a custom integer class 2.0

As sort of a follow up to my previous question from a year ago, what are some suggestions you can think of that will improve this code, whether is directly programming related or algorithm related? I ...
4
votes
2answers
310 views

Storing three integer values

Consider an 8-bit complier, in which we have an integer of size, say 2-words i.e. 16-bits or 2 bytes. You need to store three integer values which are supposed to be as: ...
6
votes
2answers
2k views

Integer to String recursive method

I was experimenting with lists, sets, and finally maps when I spotted a pattern in my code to make it recursive. Now I haven't used recursion much in the past or at work and I was very excited to have ...
31
votes
5answers
30k views

Int overflow check in Java

I have a piece of code that takes a couple of integers and check if performing an addition on the inputs would result in an overflow. I was wondering if this code is SOLID: ...
7
votes
2answers
8k views

Implementation of itoa()

How can this solution be improved? ...
10
votes
1answer
5k views

Converting a range of integers from a string to an IEnumerable

Goal Convert the following into an IEnumerable of integers accounting for the x-y ranges: ...
14
votes
2answers
19k views

Converting Roman numerals to integers and vice versa

...
7
votes
2answers
415 views

Writing data of a certain integer type to a buffer

I have function which writes data of a specified type to a buffer. Here is the part of this which writes Uint8, Uint16, ...
7
votes
3answers
2k views

Custom integer class for calculating crypto algorithms

How can I improve upon this integer class that I wrote? I am/will be using this for some calculation intensive crypto algorithms, mainly POLY1305AES. I might even write RSA using this. I know that ...
6
votes
2answers
3k views

Avoiding the 'possible loss of data' compiler warning

I'm writing a file I/O DLL in C++ which is going to be used from VB6. The interface is already fixed, and uses INT64/Currency as the general integer data type. Now I have this function: ...
7
votes
1answer
7k views

Combining two 32-bit integers into one 64-bit integer

long long combine(unsigned int high, unsigned int low) { return ((unsigned long long) high) << 32 || low; } Is there a better name for the operation? Is ...
7
votes
2answers
752 views

Terminating a C loop when maximum hardware limit reached

In response to the SO question C: f>0 vs Perl: $f>0?, the use of overflow to terminate the loop is referred to as "poor programming practice". Paraphrased: Your c code is actually exiting because ...
5
votes
4answers
281 views

Adjusting integer based on multiple elements in int array

I'm working with the following code which adjusts an int based on multiple elements of an integer array. I am wondering if there's a cleaner, easier-to-read construct for this: ...
5
votes
1answer
869 views

Branch-and-bound based IP solver

I've written this rather naïve branch-and-bound based IP solver. Are there any obvious JavaScript optimisations that could speed it up? I am not looking for asymptotically better algorithms, just ...

1
3 4 5 6
7