Questions tagged [integer]

Common datatype in many programming languages for representing both negative and non-negative whole numbers. Use this tag for questions about using, storing, or manipulating integers. For 64-bit integers, use the [long-integer] tag instead.

An integer is a whole number that can be negative, positive, or zero. For example, -2, -1, 0, 1, 2. In many programming languages, the integer data type is commonly represented as 32-bits, but may also be 64-bits (Usually referred to as the Long data type).

For 32-bit integers:

  • The signed range is : -2147483648 to 2147483647.
  • The unsigned range is : 0 to 4294967295.

For 64-bit integers:

  • The signed range is : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • The unsigned range is : 0 to 18,446,744,073,709,551,615.

For further reading, see the Wikipedia article on integers.

13448 questions
5
votes
3 answers

Cannot convert all hex values to binary

Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); System.out.println(input); int a = Integer.parseInt(input.substring(2), 16); System.out.println(Integer.toBinaryString(a)); Above mentioned code that takes in hex value…
Yeram Hwang
  • 99
  • 1
  • 1
  • 10
5
votes
2 answers

How to sort array of integers with zeros at the end?

I need to sort arrays by integer field, with 1-n sorted at the beginning and zeros last: 0,0,3,1,2 -> 1,2,3,0,0 I don't know how to sort it in one go, so I tried in 2 sorts, but it doesn't produce correct results: It does put zeros at the end, but…
Mike Torrettinni
  • 1,816
  • 2
  • 17
  • 47
5
votes
3 answers

Convert string element to integer (C++11)

I am trying to convert string element to integer using stoi function in C++11 and using it as parameter to pow function, like this: #include #include #include #include using namespace std; int main() { …
Akhmad Zaki
  • 419
  • 7
  • 23
5
votes
5 answers

would doing arithmetic operation on a pair of signed and unsigned numbers be legal?

I'm more than half way through learning assembly and I'm familiar with the concept of how signed and unsigned integers are presented in bits, I know that it might seem a weird question of which the answer would be pretty obvious, but I'm wondering…
Pooria
  • 2,017
  • 1
  • 19
  • 37
5
votes
2 answers

Reproduce behavior MAX_VALUE and MIN_VALUE

The following also applied to other MIN_VALUE and MAX_VALUE, but let's only focus on Integer for now. I know that in Java integers are 32-bit, with Integer.MAX_VALUE = 2147483647 (231-1) and Integer.MIN_VALUE = -2147483648 (-231). When calculating…
Kevin Cruijssen
  • 9,153
  • 9
  • 61
  • 135
5
votes
8 answers

How to convert string to integer without using library functions in Python?

I am trying to convert a = "546" to a = 546 without using any library functions.
Dennis M.
  • 107
  • 1
  • 2
  • 7
5
votes
4 answers

Bit level operations, get a bit from a short value

I'm trying to get the following result 00000000000000101 from this input 5. This my code and it doesn't make sense: public static int get16Bits(int x) { System.out.println((x & 0xffff) - ((x & 0x8000) << 1)); return (x & 0xffff)…
user7664681
5
votes
5 answers

what integer width processed faster in C?

Is there difference in speed when I use 16-bit width or 32-bit width integer on 32-bit CPU? Or, 32-bit vs 64-bit int on 64-bit arch? In other words, if I have some value that fit into uint16_t ranges, should I use "unsigned int" instead if…
S.J.
  • 133
  • 6
5
votes
6 answers

How do I print an integer with a set number of spaces before it?

C has printf("%Xd", Y);, which just prints the integer X and makes it take Y spaces on the console window. For example: printf("%3d", 10); console: " 10"` printf("%5d", 5); console: " 5" How do I use this in python 3?
dor barlev
  • 71
  • 1
  • 3
  • 6
5
votes
4 answers

Convert fraction to decimal number

i'm doing some exercises in my Java book. I'm very new to programming. Therefore, notice (in the code) that i'm still on Chapter one. Now I already did everything, I just want a confirmation if this is legitimate so I can feel free to move on next.…
Racket
  • 327
  • 3
  • 6
  • 15
5
votes
2 answers

How do I always round a number down in Ruby?

For example, if I want 987 to equal "900".
Jesse McCann
  • 55
  • 2
  • 7
5
votes
2 answers

output raw binary integer in php

In PHP, I have some integer variables with values from 0-65535. I need to echo/print it directly, NOT as a printed sequence of characters like printing the string "1281" but the raw binary value. Also I need it so the binary integer sent to the…
David Chen
  • 301
  • 1
  • 3
  • 4
5
votes
4 answers

List of integer ranges in C#

I have a few classes that have a sequence of integer, those sequences are registered in another class that checks if a number in the sequence isn't already used. The sequences are for the most contiguous, going from a number to another. For now I've…
Dennis
  • 83
  • 7
5
votes
6 answers

How to accept the input of both int and float types?

I am making a currency converter. How do I get python to accept both integer and float? This is how I did it: def aud_brl(amount,From,to): ER = 0.42108 if amount == int: if From.strip() == 'aud' and to.strip() == 'brl': …
Katrina
  • 111
  • 2
  • 2
  • 10
5
votes
2 answers

Haskell int list to String

I would like to know if there is a simple way to turn [5,2,10] into "52a". Where its not just to this case, I want to associate any number >9 with the corresponding letter. Thanks in advance.
Mares
  • 53
  • 1
  • 4