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.

349 questions
Filter by
Sorted by
Tagged with
5k views

Convert a numeric string to number but without python's built in function

I'd like to get a code review and some insights of whether I chose a good way to do this. What would other, clever ways look like. ...
13k views

Implementation of C Standard Library Function ntohl()

This is an implementation of ntohl() that I wrote as an exercise. ntohl() takes a uint32_t ...
87 views

From a string of 3 numbers to 3 integers

I'm solving some puzzles to learn Rust. A problem I faced is to turn a string of 3 integers into 3 integers. I succeeded with the following example: ...
58 views

Storing angles with overflow errors

Rather than checking if my angle is in the range of 0 to 2pi every time it gets set, I got the idea to store it as an unsigned short with 0xFFFF being +2pi, thus the standard overflow behavior for ...
111 views

Enforcing correct input/output of integers

The problem: Some types, like cstdint aliases or, at least purely theoretically, even std::size_t, may be (but don’t have to be)...
643 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 ...
443 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 ...
147 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. ...
933 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 ...
762 views

Construct: VarInt integer encoding

This code is part of the Construct library. Docstrings explain what the code is supposed to do. ...
134 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 ...
196 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: ...
3k 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 ...
38k views

Converting a bytearray into an integer

I am working on a program to decode MMS PDU files. They are binary files and I am reading them byte by byte and decoding each header value as I come to it. One header value is the Date, and it's ...
7k 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 ...
395 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 ...
518 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. ...
113 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 ...
2k views

Unsigned integer division ARM Cortex-M0+ Assembly

I am writing a subroutine for unsigned integer division in Assembly. I will call the subroutine DIVU. Inputs: R1 will be the ...
91 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 ...
250 views

I am looking for suggestions of improving this function to check whether a memory address is appropriate or not. ...
193 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 ...
6k views

Finding the smallest missing positive number in an array

Any suggestions to improve? ...
2k 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 ...
195 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 ...
60 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 ...
1k views

Convert NSInteger into NSString

This is my sample code to convert a integer into string. Is it very costly to do the multiple loops of [NSMutableString stringWithFormat:..]? I.e should I just use appendString and get the NSString ...
5k 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 (...
2k views

983 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 ...
813 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 ...
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 ...
3k views

Simple calculation program in assembly MASM

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

Concatenate three 16-bit integers in one 64-bit integer with C++

I am looking for an elegant alternative of the following code where wordXX contains always 16 bits: ...
1k views

Portable byte order conversion

I'm trying to improve the portability of a file format converter, specifically to POSIX platforms other than Linux. I'd appreciate a review of the following functions used for converting between ...
4k views

Python combine two integers to a third

We have three integers: A, B, C where the first (i.e. the most significant) digit of C is the first digit of A, the second digit of C is the first digit of B, the third digit of C is the second ...
117 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 ...
110 views

Multiple base numbers parser

This code is a Parser that parses numbers according to R5RS. #b1001 - binary #o2127 - octal #h02d - hexadecimal #d1231 - decimal 3923 - decimal It is working ...
61 views

Turning an Integer into an array of ints

My goal here is pretty simple, I want to turn a number like 12435987234 into an array of integers in reverse order. So that would look like: ...