Integers - signed and unsigned

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Integers - signed and unsigned

Post 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?
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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>
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post 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)
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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:
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Alright... that makes sense enough. This is because computers do not really understand negative numbers, right?
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post 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
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post 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.
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I hate the word n00b
::shudders::
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

The Ninja Space Goat wrote:I hate the word n00b
::shudders::
k. some dude that is still green
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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!
Last edited by Luke on Tue Jul 11, 2006 2:55 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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?
(#10850)
Post Reply