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
0 votes
1 answer
21 views

C++20 Wrapper class for an unsigned integer type and a templated derived class that codes modular arithmetic type

The context is a library to represent numbers (in this case integers) by wheighted position by radix powers for every radix R, passed as template argument. These derived types are digits of radix R, ...
user avatar
3 votes
1 answer
50 views

Quickly read numeric input

Do you have any criticisms or corrections or improvements? I need to read only numbers(and this numbers could be from 0 to 1000000) ...
user avatar
2 votes
1 answer
68 views

Encode non-negative integer to a string of ascii letters and digits

I want to encode a non-negative integer to ASCII letters and digits. I wrote below code for that, that works, but which I assume too immature to use in production. ...
user avatar
1 vote
1 answer
42 views

C code for discovering numbers with interesting/beautiful/symmetric properties

Below is a C code that generates 1000 random positive integers, for each number we check primality, palindromic property, and the square root of the sum of the digits. The purpose is to find/discover ...
user avatar
  • 1,142
3 votes
1 answer
216 views

Format an integer with space as thousand separator

I need to format a number with space as thousand separator in my Java code for Android. How can these functions be improved? What are the pros and cons to the first recursive method? What are the ...
user avatar
19 votes
4 answers
2k views

Minimal `printf` for integer types in x86 assembly

I'm writing a minimal C runtime targeting an old 32-bit Windows XP machine as a personal project. The C runtime provided by compilers is quite bloated. I wouldn't mind some library bloats up to ...
user avatar
  • 411
4 votes
3 answers
583 views

C++ money class for basic banking application

I wanted to get my code reviewed as I have tried to implement a basic Money class to represent money values in c++. Can anyone tell me if I am implementing my basic arithmetic operator overloads ...
user avatar
6 votes
3 answers
316 views

Count the numbers in a range in which the sum of the odds digits have the same parity of the evens one

As already written in the title I want to count the numbers in the range (x+1, y) where x and y are integers, in which the sum of the digits in odd places have the same parity of the ones in even ...
user avatar
  • 163
0 votes
3 answers
141 views

Converting whole numbers to binary in C/C++

...
user avatar
  • 1
2 votes
3 answers
199 views

Convert string to integer and catch errors

I have attempted [and made one] function to convert string to integer and catch errors in pure c Working method The whole working method is present in code itself The header file The str2num.h here:- <...
user avatar
  • 77
1 vote
0 answers
51 views

Displaying Submitted Links Securely On Your Pages

I wanted to allow my website visitors (any Tom, Dick & Harry) submit their links to my webpage for output on my page. I thought it's best to parse user submitted urls before echoing their ...
user avatar
1 vote
1 answer
78 views

A simple Java integer integer hash set - follow-up 2

(See the previous version.) Now I have this: com.github.coderodde.util.IntHashSet: ...
user avatar
  • 25.3k
1 vote
0 answers
61 views

A simple Java integer hash set - follow-up

(See the previous version.) (See the next version.) After incorporating changes in the previous post, I came up with this implementation. However, I left hashing as it is. ...
user avatar
  • 25.3k
6 votes
4 answers
1k views

A simple Java integer hash set

(See the next version.) The following data structure implements a hash table based set for int values: ...
user avatar
  • 25.3k
1 vote
3 answers
67 views

Validating an integer with affixes in compile-time or runtime

I'm implementing a function called is_proper_integer that will check the string whether it is a valid integer literal by borrowing the idea from C++ grammar. ...
user avatar
1 vote
2 answers
200 views

Unsigned 64bit subtract-with-borrow in Standard C++

I'm writing a (compile-time-)fixed-width unsigned big integer. To implement subtraction, a subtract-with-borrow primitive is required. When efficient platform-specific implementation isn't available (...
user avatar
0 votes
3 answers
139 views

Luhn algorithm using Stream API

Example ...
user avatar
2 votes
1 answer
87 views

Safe runtime numeric casts

The rationale behind this code is to implement a runtime-safe number conversions in situations when precision loss is possible, but is not expected. Example: passing a ...
user avatar
  • 121
2 votes
1 answer
212 views

Write a Kotlin-function isPrimeNumber

Exercise: Write a prime number-test isPrime(num: Int), which for integer m >= 2 checks, if the integer is a prime number or not. My solution: ...
user avatar
  • 3,758
0 votes
1 answer
39 views

optimize integer validation

I have some classes with properties, wich could only have numeric values in a given range (e.g. 0 to 8). This should be validated and wrong values prevented with an exception. The given behavior may ...
user avatar
  • 103
5 votes
2 answers
2k views

Represent integer as binary in C

To practice my C, I've written a small function in C to display an integer as an 8-bit binary number. Please let me know how to improve this function, and other C-style coding conventions. Thanks! <...
user avatar
  • 9,466
6 votes
3 answers
222 views

Fastest (in clock cycles) 16-bit x 16-bit unsigned integer division algorithm for ATMEGA1284?

I am trying to create an optimized 16-bit division algorithm for the AVR ATMEGA1284. The goal is to reduce the number of clock cycles as much as possible. AVR INSTRUCTION SET MANUAL: https://ww1....
user avatar
  • 169
2 votes
1 answer
506 views

C++: swapping bytes of an uint64_t

This question is about swapping bytes of an uint64_t value, or in other words, about converting between endianness of an integer value: ...
user avatar
  • 25.3k
3 votes
1 answer
249 views

Integer version of c++ standard library midpoint

I was extremely annoyed by the lengthy, edge-case-galore explanation of integer version of C++ standard library mindpoint implementation here, so I made my own simple 2's complement version. I present ...
user avatar
  • 61
4 votes
4 answers
828 views

Convert Integer to Binary String

This code takes a user input number which is a positive integer, and outputs a string representation of the number in binary. For example, input 2 outputs ...
user avatar
2 votes
2 answers
2k views

Football management game in C++

Recently, I have been working on a College Football Manager game, in which you coach a team from the ground up. I have successfully made it to where you can win games, lose games, and change your team ...
user avatar
3 votes
2 answers
225 views

How to simplify and optimize bitwise get/set operations on a large bit buffer in JavaScript?

tl;dr: How could you rewrite the buf_get and buf_set functions below to be most optimal? It took me a long time and a lot of ...
user avatar
  • 299
2 votes
1 answer
106 views

Converting an integer to a hexadecimal string representation in Java

I have rolled my own Java method for converting ints to the hexadecimal Strings: ...
user avatar
  • 25.3k
8 votes
2 answers
1k views

Swapping bytes of an integer in Java

I have this tiny function that expects an int and returns an int with the bytes swapped: ...
user avatar
  • 25.3k
5 votes
2 answers
521 views

How to optimize bitwise get/set/clear of ranges of bits on 8-bit integers in JavaScript?

I have been working for a few days on writing get, set, and clear bitwise functions in ...
user avatar
  • 299
-3 votes
1 answer
298 views

Return reversed integer - Java [closed]

The question is from Leetcode. Given a 32-bit signed integer, reverse digits of an integer. ...
user avatar
3 votes
1 answer
102 views

Implementation of itoa

...
user avatar
  • 1,353
4 votes
5 answers
2k views

Convert Integer to String without using Java API library

I have written a Java program that converts an integer to String digit by digit and concatenate them together using the + operator without touching the Stock Java API library. I like to have feedback ...
user avatar
  • 297
4 votes
1 answer
49 views

Large number stored as vector, increase performance

I made a code to initialize char vectors with random numbers representing very large numbers with more than 20.000 digits. The additions and multiplications are correct but my code is too slow (1 ...
user avatar
  • 41
2 votes
2 answers
293 views

Reading and Storing Integer from Serial Monitor

Description I wanted to understand how integers can be written and stored inside variables without the use of Serial.parseInt(). I couldn't find any code examples about this. Perhaps this is the ...
user avatar
5 votes
1 answer
346 views

HugeInt division using base 2^32 implementation

I previously submitted my code for a HugeInt class here. That version lacked a long division implementation. I have now implemented (long) division using Donald Knuth's algorithm D, following the ...
user avatar
3 votes
1 answer
735 views

Plotting the integer values in text format in matplotlib piechart

I have done a clustering algorithm and represented the results in a pie chart as shown below. ...
user avatar
  • 33
12 votes
3 answers
2k views

Huge integer class using base 2^32 (was 256) follow up

Thanks again to everyone for their very useful suggestions concerning a huge integer class I posted here several days ago. I have made many of the suggested changes, perhaps the biggest being in the ...
user avatar
21 votes
2 answers
3k views

Huge integer class using base 256

After a hiatus, I have returned to coding in C++. In an effort to learn some of the newer aspects of the language and for exercise and 'up-skilling', I am writing some simple classes and this ...
user avatar
2 votes
1 answer
54 views

"Reflecting" addition

I'm implementing the following function for signed integer numbers: given endpoints of a closed interval lo and hi, and inputs <...
user avatar
  • 202
6 votes
3 answers
256 views

Safe Integer Library in C++

I've designed a single-file safe integer library in C++. It catches undefined behavior prior to integer overflows or underflows and throws the respective exceptions. I intend this to be portable, to ...
user avatar
  • 1,705
4 votes
2 answers
279 views

converting bits binary to bcd

I wrote a code that requests user input and then converts binary to bcd then back to binary using bitwise operations. While I think my code is good I want to know if there is a better way to write the ...
user avatar
6 votes
2 answers
495 views

C - manually parsing char* into integer

I'm trying to parse a char* into an int without using atoi(). I walk through the string, ...
user avatar
3 votes
1 answer
2k views

Codewars: Sum Strings

Sum Strings Codewars kata. It's supposed to be able to handle big integers.   Question Given the string representations of two integers, return the string representation of the sum of those integers. ...
user avatar
  • 1,796
4 votes
1 answer
470 views

Computational verification of Collatz conjecture using OpenCL

This code review request follows my previous request Computational verification of Collatz conjecture. Unlike the previous program (which was designed for the CPU), this code should run on modern GPUs....
user avatar
  • 249
4 votes
1 answer
100 views

Manually formatting numbers in Python

I was working on a little Python challenge that was a bit more difficult than expected: format any non-negative number so 1000 turns into ...
user avatar
  • 289
9 votes
2 answers
602 views

Converting integers into Unary Notation

I have written a python script that has tallies representing digits 1-9 (0 is just ":" ) Unlike true Unary languages that are in the form 1^k. I represent values for n as per their decimal digits. The ...
user avatar
0 votes
2 answers
89 views

Python code to continue if a certain type is seen, otherwise try again to get valid input [closed]

I am very very new to programming, and this is my first day using Python. I want to check to see if an input is of type 'int' and to proceed with my program if the user has entered an 'int', ...
user avatar
3 votes
2 answers
103 views

Computational verification of Collatz conjecture using gmplib

Prerequisites The unsigned long type has a size of 64 bits. The following macros are defined. ...
user avatar
  • 249
3 votes
1 answer
349 views

Computational verification of Collatz conjecture

Prerequisites The typedef name uint128_t designates an unsigned integer type with width exactly 128 bits. The ...
user avatar
  • 249

1
2 3 4 5
8