Page 1 of 2

Integers - signed and unsigned

Posted: Tue Jul 11, 2006 10:43 am
by Luke
I have come across this terminology a number of times - signed and unsigned integers. I have looked the concepts up on Google, but the explanations I have read made very little sense. Anybody have an idiot's answer?

Posted: Tue Jul 11, 2006 10:56 am
by matthijs
Unsigned is without a + or - sign. Integers are signed by default. They can contain positive and negative values. That's why if you use INT UNSIGNED for a db field in MySQL, it can hold twice the maximum value. The range stays the same though.

Posted: Tue Jul 11, 2006 10:56 am
by Oren
Well, you asked for "idiot's answer" so here it is:
<idiot's answer>Unsigned integers can hold a larger value than the equivalent signed</idiot's answer>

Posted: Tue Jul 11, 2006 10:59 am
by GM
Use "Unsigned" in your columns if you know that the integer is always going to be positive (eg: id fields, number of posts in a forum etc.)

The default is signed, and this means that the integers can also be negative. (ie: temperature log)

Posted: Tue Jul 11, 2006 11:08 am
by MarK (CZ)
Integral types may be unsigned (capable of representing only non-negative integers) or signed (capable of representing negative integers as well).
Wiki: Integer (computer science)
:D

Posted: Tue Jul 11, 2006 11:26 am
by Oren
matthijs wrote:That's why if you use INT UNSIGNED for a db field in MySQL, it can hold twice the maximum value. The range stays the same though.
Twice + 1 :wink:

Posted: Tue Jul 11, 2006 12:14 pm
by Luke
Alright... that makes sense enough. This is because computers do not really understand negative numbers, right?

Posted: Tue Jul 11, 2006 12:31 pm
by MrPotatoes
they do. it's in the binary.

it's not going to be any faster

just remember to choose the correct type, you don't want over flow. that means taht you've reached the max number and you go back to zero. that my friend would blow some serious balls

Posted: Tue Jul 11, 2006 12:39 pm
by jamiel
Haha - Indeed. *knows one of his tables currently sitting on 155862968 records*

For interests sake, the signed range of a normal INT in MySQL is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

Posted: Tue Jul 11, 2006 1:22 pm
by MrPotatoes
well when you are starting out and you get an overflow error (C/C++ -> Games) you don't know what the hell you did or why it's screwing up until someone tells you what is wrong. it's not fun. not fun at all.

but funny when you see a n00b do it

Posted: Tue Jul 11, 2006 1:39 pm
by Luke
I hate the word n00b
::shudders::

Posted: Tue Jul 11, 2006 1:45 pm
by Christopher
jamiel wrote:For interests sake, the signed range of a normal INT in MySQL is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
Indeed the answer to this question is a very practical one -- especially in the early days of computers. Maintaining a numbers sign required an additional bit, effectively reducing by half the maximum value that could be stored. That can make a large difference in the range, so chips and programming languages allowed the use of integers without a sign bit when the programmer need a higher max but no negative numbers.

Posted: Tue Jul 11, 2006 1:50 pm
by MrPotatoes
The Ninja Space Goat wrote:I hate the word n00b
::shudders::
k. some dude that is still green

Posted: Tue Jul 11, 2006 1:52 pm
by Luke
MrPotatoes wrote:
The Ninja Space Goat wrote:I hate the word n00b
::shudders::
k. some dude that is still green
LOL can you imagine people in forums all replacing the word n00b with "some dude that is still green"
some forumer wrote:Man, you don't know the square root of 11,212,124?? you some dude that is still green!

Posted: Tue Jul 11, 2006 2:31 pm
by Christopher
MrPotatoes wrote:k. some dude that is still green
How can a dude be still green when the word dude itself means green (and well dressed). A n00b n00b with bling?