# 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.

318 questions
Filter by
Sorted by
Tagged with
572 views

### Counting the number of “on” bits in an int

Here is some code I wrote as a solution to Programming Exercise 15.3 in Stephen Prata's C Primer Plus, 6th Edition. It is probably worth pointing out that the title of the chapter is Bit Fiddling. The ...
112 views

Link to original question: Successful use of strtol() in C After getting excellent feedback from the code review community I attempted to redo my string to long conversion program! I believe I ...
789 views

### Corrupting Java arithmetic through reflection

Inspired by a PPCG answer, I wrote this code, which shuffles the autoboxing caches of Number subclasses. This leads to, among other things, outputting ...
365 views

### Number representation for a calculator that works with very big numbers

I'm a beginner: I have learned concepts and features which I think I need in my project, but this is my first serious program and it is my internship project. I'm totally confused and need help to ...
748 views

### Maximum product of 3 integers in an int array using Python

This is an interview question from Interview Cake: Given a list_of_ints, find the highest_product you can get from three of the integers. The input list_of_ints will always have at least three ...
139 views

### Maximum product of 3 integers in an int array using Python - follow up

This is a follow up to Maximum product of 3 integers in an int array using Python Changes to the code include renamed variables for improved readability and I added more test cases. ...
604 views

### Construct: VarInt integer encoding

This code is part of the Construct library. Docstrings explain what the code is supposed to do. ...
93 views

### Program to determine ranges of char, short, int and long variables, both signed and unsigned

I wrote code to determinate ranges of char,short int and long variables,both signed and unsigned.Please help me to improve my code :) Here is the code: ...
2k views

### Successful use of strtol() in C

Attempted to use strtol() to parse a string into an integer and to output any appropriate error messages for failed conversions. How did I do? How could/should it ...
3k views

### Integer-to-ASCII algorithm (x86 assembly)

This is my best effort at converting a 32 bit integer in EAX, to an 8 character ascii string (result in RDI). It will work ...
296 views

### Dividing Negative integer ranges

Context: My project has a hand-rolled ORM (... yeah ... I know) ... built around the MS DataSet objects that represent wrapped collections of rows of DBtables (... yeah ... I know) ... and which ...
382 views

### Converting bits to decimal (integer) string is so slow

I am implementing myself a BigInteger class. It can natively handle very very big digits in very short time. ...
90 views

### Finding shortest sequences of integers whose product is larger than n

Here is the task: For an integer n, return a list of the k length integers sequences whose product is larger than n but as close to n as possible (i.e. smallest larger than n number), and whose ...
181 views

### Valid memory address in Python

I am looking for suggestions of improving this function to check whether a memory address is appropriate or not. ...
86 views

I want to make some VHDL code open source. But before I do, I want to make sure that it is as readable as possible. Things to improve upon could for example be naming and the use of comments. The ...
7k views

### All-in-one number base converter

I coded this program as a challenge for /r/dailyprogrammer. Basically this program can convert any number from any base to another base including negative bases as long as the input is coherent. Did I ...
90 views

### Translating binary data from a file into a very large base-ten integer

I'm making an experimental Java algorithm that translates binary data from a file into a (very large) base ten integer. I am using BigInteger since this number may ...
5k views

### Finding the smallest missing positive number in an array

Any suggestions to improve? ...
1k views

### Variable length integer encoding in Java

I have coded up the variable length integer encoding aka VLQ in Java. It works with any base in (1, 128]. I've implemented the usual encode/decode methods and also ...
184 views

### Number class to add/compare different kinds of numbers

I am creating a Number class having Integer and Fraction derive class which add/compare different kinds of numbers. In addition, the caller need not needs to know ...
1k views

### HackerEarth Girlfriend's Demand challenge, solved two ways

I solved the Girlfriend's Demand challenge on HackerEarth. In summary: Input: First line of the input contains a string S. Next line contains an integer Q, the number of queries. Each of the next ...
54 views

### Dividing a long (arbitrary-precision) number by an integer

As part of a (slightly) larger program, I needed to write a function that could take an arbitrarily large number and divide it by a small number. In this program, I will be dividing this number ...
18k views

### Counting words, letters, average word length, and letter frequency

I'm pretty sure my code is mostly correct. I think I'm having formatting errors more than anything. I keep receiving warnings about "double to float and int to float,possible loss of data. Here is ...
3k views

### Character to decimal conversion

This converts from character representation of integers to their decimal value: ...
1k views

### Arabic to Greek numeral converter, 1 - 10

One of the things that's straight-forward in JavaScript is Unicode support. If you want to return ϝ (lowercase digamma, not a simple ...
3k views

### itoa base function in C

This is a function that converts an integer value to a null-terminated string using the specified base and stores the result in a char array that I must allocate (...
1k views

1k views

### Normalize integer types to float range

I wrote two template functions to take an integer type and output a float in the given range. One function takes signed integers and the other takes unsigned ...
1k views

### Handling GetTickCount() overflow in timeouts

This is code which must run on XP, so no GetTickCount64, and which should correctly handle the value wrapping around after 49 days. Can it be improved? ...
3k views

### Mostly portable 128 by 64 bit division

I wrote this out of curiosity. It is based on the theory behind Knuth's Algorithm D and is intended to emulate the behavior of the x86 div instruction (though the ...
335 views

### Merge and sorting arrays of String and int in more efficient methods

Are there better methods for merge and sorting arrays of int and String in more efficient methods both time-complexity wise and ...
1k views

### Portable safe unsigned integer arithmetic

tl;dr The purpose of the code is to allow writing ...
144 views

I have implemented the LEB128 encoding for unsigned integers. I'm fairly new to Haskell so I have some doubt about the coding style I'm using, particularly the definition of ...
1k views

### Large integer class for storing integer data as a char array

I am working on a LargeInteger class to store Integers beyond the size of long long as a dynamic character array. I have ...
112 views

### Safe, fully standards-following integer abs in C

Here's a bit tricky one, because AFAIK there is no existing platform, where conditionally compiled part of the code would actually get included by compiler, so it is entirely up to the human review to ...
9k views

### Checking endianness at compile-time

I've tried to make a portable way of ensuring endian-specific code gets generated at compile time using C++11, however I only have a computer with Windows on it to test at the moment. Because of this, ...
334 views

### Calculating the sum of the digits in 2^1000

I have a program which calculates the sum of the digits in the number 21000. The program is not beautiful and I was hoping for some advice on how to improve it. The idea I have used is to create an ...
315 views

### String-casting utility functions

I wrote a small header that is supposed to take care of calling the right strtoX or or stoX function for me and doing so at ...
42k views

...
70 views

### read re-implemented for Int's

I have written a safe read function for haskell (for education!). I think this is fairly idiomatic haskell code, but I'd like to know for sure. If you see anything else that could be improved, please ...
2k views

### Simple calculation program in assembly MASM

I am a beginner in assembly. This program calculates: (Z+Z)+(X-Y) ...
268 views

### Get number from N

I'm trying to find the shortest and best way to achieve the following: Given input integer \$N, get the following output: n = 0, output = 0 n = 1, output = 0 n = 2, output = 10 n = 3, output = 100 ...
187 views

### Comparing a string that can hold a numeric value

I am refactoring a part of big old system developed in Java. I came across a situation where we are migrating some data types, and there will be use of both types. For compatibility, as all the old ...
2k views

### Converting a string to an Integer in C

I'm learning C and one of the questions I've been asked is converting a string to an integer. The code I've written supports converting from a string in any base up to 16/hex to an integer. There is ...
17k views

### Conversion functions between binary, hexadecimal and ASCII

I've written a small suite to easily convert my data between binary, hexadecimal and ASCII: ...