Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 07-13-2007, 02:25 AM Unsigned vs Signed
mwsource's Avatar
Skilled Talker

Posts: 61
Name: Reid
Location: Georgia, USA
Trades: 0
Hey again,

So I'm working on a web app and I need a little guidance as to what the differences are between signed and unsigned values. I did a search but didn't find enough information to understand the differences and consequences of using either in regards to performance.

I appreciate your replies!
__________________
Reid Workman -
Please login or register to view this content. Registration is FREE
- Currently Working on a Freelance Job search: PM me if you are interesting in testing it.
mwsource is offline
Reply With Quote
View Public Profile Visit mwsource's homepage!
 
 
Register now for full access!
Old 07-13-2007, 03:15 AM Re: Unsigned vs Signed
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Signed means you'll be able to store positive and negative numbers. Unsigned will only be storing positive numbers.

Obviously if you need to account for negative numbers you have to use signed. If you don't then you'll probably want unsigned numbers since it effectively doubles the range of positive numbers.

Signed -127 to +128
unsigned 0 to 255

I'm not sure if there's any consequence in performance. I think it's more to do with whether or not you anticipate storing negative numbers.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-13-2007, 03:56 AM Re: Unsigned vs Signed
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
The number 0 is expressed as 00000000 and 255 as 11111111. Signed means the first bit represents whether the number is negative or positive; whether the plus or minus "sign" is a variable that needs to be accounted for. Unsigned means the first bit is treated like the rest of them. In either case, the same data is stored, it's just a matter of how it's interpreted.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 07-14-2007, 01:18 AM Re: Unsigned vs Signed
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I thought that's how it worked Forrest, but I wasn't 100% sure so I held back that bit of information. I knew someone would be along to fill it in.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-15-2007, 12:36 AM Re: Unsigned vs Signed
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Well knowing it doesn't really help in 90 % of real life situations. Nobody goes in and manipulates bits directly, we all do higher level operations. But it's an interesting bit of trivia...

It's also interesting that the range doesn't change based on whether the first bit describes + vs - instead of another digit. 0 to 255 is 255 unique outcomes, and so is -127 to 128. Just like you can use floating points, or you can use scale and precision to move the decimal around, in this case you have a window of 255 slots, and you get two choices where to place that window.

But the real-world application for this knowledge is that if it's an identity column ( 1, 2, 3 ) that goes sequentially instead of using random numbers, you should use unsigned. You'll never have a negative value, and in most cases you can get away with a 32 bit int instead of a 64 bit long. Going unsigned puts the ceiling at about 4 billion instead of 2.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 07-15-2007, 01:19 AM Re: Unsigned vs Signed
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
The range being the same is the reason I wondered about the first bit being used for the sign, but now that I think about it why would it. You lose that bit for the absolute number, but because you get the negative side of the equation you still get the same range.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Unsigned vs Signed
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23078 seconds with 12 queries