Questions tagged [unsigned-integer]

A specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number.

In typed languages, an unsigned integer is a specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number. It can also represent integers twice the magnitude of the signed integers for the same width since no bit is used up to indicate the sign.

591 questions
193
votes
9 answers

What is the benefit of zerofill in MySQL?

I just want to know what is the benefit/usage of defining ZEROFILL for INT DataType in MySQL? `id` INT UNSIGNED ZEROFILL NOT NULL
xkeshav
  • 53,360
  • 44
  • 177
  • 245
191
votes
6 answers

Why unsigned integer is not available in PostgreSQL?

I came across this post (What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL?) and realized that PostgreSQL does not support unsigned integer. Can anyone help to explain why is it so? Most of the time, I use unsigned…
Adrian Hoe
  • 2,081
  • 2
  • 12
  • 12
146
votes
5 answers

What is the difference between signed and unsigned int

What is the difference between signed and unsigned int?
Moumita Das
  • 1,485
  • 2
  • 12
  • 5
123
votes
4 answers

Why are unsigned int's not CLS compliant?

Why are unsigned integers not CLS compliant? I am starting to think the type specification is just for performance and not for correctness.
doekman
  • 18,750
  • 20
  • 65
  • 86
111
votes
8 answers

Why doesn't SQL Server support unsigned datatype?

I am specifically thinking about unsigned int. Here is a practical example: what do you do when your identity column maxes out? It's possible to either go BigInt (8 bytes storage instead of 4) or to refactor the application to support negative…
Romhein
  • 2,126
  • 2
  • 17
  • 17
92
votes
6 answers

A warning - comparison between signed and unsigned integer expressions

I am currently working through Accelerated C++ and have come across an issue in exercise 2-3. A quick overview of the program - the program basically takes a name, then displays a greeting within a frame of asterisks - i.e. Hello ! surrounded framed…
Tim Harrington
  • 923
  • 1
  • 7
  • 4
70
votes
4 answers

Why is size_t unsigned?

Bjarne Stroustrup wrote in The C++ Programming Language: The unsigned integer types are ideal for uses that treat storage as a bit array. Using an unsigned instead of an int to gain one more bit to represent positive integers is almost never a good…
Jon
  • 5,275
  • 5
  • 39
  • 51
64
votes
8 answers

Why are unsigned integers error prone?

I was looking at this video. Bjarne Stroustrup says that unsigned ints are error prone and lead to bugs. So, you should only use them when you really need them. I've also read in one of the question on Stack Overflow (but I don't remember which one)…
Destructor
  • 14,123
  • 11
  • 61
  • 126
56
votes
3 answers

MySQL datatype INT(11) whereas UNSIGNED INT(10)?

in MySQL if we create a field dataType of INT and does not specify any length/values then it automatically became int(11) and if we set the attribute UNSIGNED or UNSIGNED ZEROFILL then it turns into int(10) Where does this length(1) goes?
xkeshav
  • 53,360
  • 44
  • 177
  • 245
54
votes
2 answers

How can I get the size of an std::vector as an int?

I tried: #include int main () { std::vector v; int size = v.size; } but got the error: cannot convert 'std::vector::size' from type 'std::vector::size_type (std::vector::)() const noexcept' {aka 'long unsigned…
Flashpaper
  • 571
  • 1
  • 5
  • 5
49
votes
2 answers

Cython: (Why / When) Is it preferable to use Py_ssize_t for indexing?

This is a follow-up to this question. (Why / When) Is it preferable to use Py_ssize_t for indexing? In the docs I just found # Purists could use "Py_ssize_t" which is the proper Python type for # array indices. -> Does that mean always when…
embert
  • 7,336
  • 10
  • 49
  • 78
47
votes
4 answers

Using MySQL's TIMESTAMP vs storing timestamps directly

I'm in a dilemma about saving date and time values in MySQL's TIMESTAMP format vs in a custom UNSIGNED INT format. The main considerations here are speed of retrieval, appropriate range calculations in PHP and occasional formatting into human…
siliconpi
  • 8,105
  • 18
  • 69
  • 107
45
votes
10 answers

How can I safely average two unsigned ints in C++?

Using integer math alone, I'd like to "safely" average two unsigned ints in C++. What I mean by "safely" is avoiding overflows (and anything else that can be thought of). For instance, averaging 200 and 5000 is easy: unsigned int a = 200; unsigned…
Tim
  • 997
  • 2
  • 11
  • 17
42
votes
5 answers

What is a difference between unsigned int and signed int in C?

Consider these definitions: int x=5; int y=-5; unsigned int z=5; How are they stored in memory? Can anybody explain the bit representation of these in memory? Can int x=5 and int y=-5 have same bit representation in memory?
Anand Kumar
  • 499
  • 1
  • 4
  • 7
37
votes
5 answers

0 value in Django PositiveIntegerField?

Can a field of type models.PositiveIntegerField contain a 0 value? I'm doing something like: points = models.PositiveIntegerField() Thanks, I know I should try it myself, but I haven't a Django environment here.
Juanjo Conti
  • 28,823
  • 42
  • 111
  • 133
1
2 3
39 40