Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 4, 2013, 05:49 PM   #1
larswik
macrumors 65816
 
Join Date: Sep 2006
Silly Signed / Unsigned question

I know the difference between Signed and Unsigned but I was curious why they call them that? I did google for the answer but the response I find explain what the difference are and not what the terminology is so I thought I would ask real quick instead?

My guess is unsigned, being only positive numbers, means there is no minus SIGN in front of it but that is only guess.

Just wondering?
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote
Old Jan 4, 2013, 05:53 PM   #2
mobilehaathi
macrumors 601
 
mobilehaathi's Avatar
 
Join Date: Aug 2008
Location: Bay Area, CA
Unsigned integers don't store any information about the sign of the number.
__________________
The true way is along a rope that is not spanned high in the air, but only just above the ground. It seems intended more to cause stumbling than to be walked along.
mobilehaathi is offline   0 Reply With Quote
Old Jan 4, 2013, 06:27 PM   #3
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
Quote:
Originally Posted by mobilehaathi View Post
Unsigned integers don't store any information about the sign of the number.
And the sign being the minus sign? So it just stores the numbers, that's it and that is why it is called unsigned and signed because of that minus sign.

So it is what I thought. Thanks for confirming it.
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote
Old Jan 4, 2013, 06:34 PM   #4
subsonix
macrumors 68030
 
Join Date: Feb 2008
Quote:
Originally Posted by larswik View Post
My guess is unsigned, being only positive numbers, means there is no minus SIGN in front of it but that is only guess.

Just wondering?
The most significant bit in a signed integer indicates if the number is negative or not, this is the sign bit. You can verify this by trying to assign (1 << 31) to a signed integer which will set the bit and result in a negative number. A signed integer have the same range but half of it is used for negative values. For more information look up two's complement to see how they are represented on modern hardware.
subsonix is offline   0 Reply With Quote
Old Jan 4, 2013, 06:34 PM   #5
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
If a number is signed, the first bit is the sign bit. A sign bit of 0 corresponds to a + sign and a sign bit of 1 corresponds to a - sign.

With unsigned numbers, there's no bit that holds the sign information.
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 4, 2013, 06:35 PM   #6
mobilehaathi
macrumors 601
 
mobilehaathi's Avatar
 
Join Date: Aug 2008
Location: Bay Area, CA
Sign being a property of a number, either positive or negative.
__________________
The true way is along a rope that is not spanned high in the air, but only just above the ground. It seems intended more to cause stumbling than to be walked along.
mobilehaathi is offline   0 Reply With Quote
Old Jan 4, 2013, 07:23 PM   #7
Doctor Q
Administrator
 
Doctor Q's Avatar
 
Join Date: Sep 2002
Location: Los Angeles
Here's an example, which assumes (since it's always true for Mac programming) that we're using the two's complement method for storing signed numbers. We're pretend we have only 4 bits in our integers:

How the 16 possible unsigned bit patterns are interpreted:
0000 means 0
0001 means 1 (which is the same as +1)
0010 means 2 (which is the same as +2)
0011 means 3 (which is the same as +3)
0100 means 4 (which is the same as +4)
0101 means 5 (which is the same as +5)
0110 means 6 (which is the same as +6)
0111 means 7 (which is the same as +7)
1000 means 8 (which is the same as +8)
1001 means 9 (which is the same as +9)
1010 means 10 (which is the same as +10)
1011 means 11 (which is the same as +11)
1100 means 12 (which is the same as +12)
1101 means 13 (which is the same as +13)
1110 means 14 (which is the same as +14)
1111 means 15 (which is the same as +15)

Conclusion: We can represent 16 different integers but all of them are positive.
How the 16 possible signed bit patterns are interpreted:
0000 means 0
0001 means 1 (which is the same as +1)
0010 means 2 (which is the same as +2)
0011 means 3 (which is the same as +3)
0100 means 4 (which is the same as +4)
0101 means 5 (which is the same as +5)
0110 means 6 (which is the same as +6)
0111 means 7 (which is the same as +7)
1000 means -8
1001 means -7
1010 means -6
1011 means -5
1100 means -4
1101 means -3
1110 means -2
1111 means -1

Conclusion: We can represent 8 different non-negative integers and 8 different negative integers.
Notice that the unsigned bit patterns don't really represent unsigned numbers. Each bit pattern in both sets represents an integer, and integers by nature always have a sign. People tend to gloss over the distinction.
__________________
Oh do pay attention 007. In the wrong hands, this 12-core Mac Pro with three 4K displays, FirePro graphics, and Thunderbolt 2 could be very dangerous.
Doctor Q is offline   0 Reply With Quote
Old Jan 4, 2013, 08:10 PM   #8
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
Quote:
Originally Posted by Doctor Q View Post
Here's an example, which assumes (since it's always true for Mac programming) that we're using the two's complement method for storing signed numbers. We're pretend we have only 4 bits in our integers:

How the 16 possible unsigned bit patterns are interpreted:
0000 means 0
0001 means 1 (which is the same as +1)
0010 means 2 (which is the same as +2)
0011 means 3 (which is the same as +3)
0100 means 4 (which is the same as +4)
0101 means 5 (which is the same as +5)
0110 means 6 (which is the same as +6)
0111 means 7 (which is the same as +7)
1000 means 8 (which is the same as +8)
1001 means 9 (which is the same as +9)
1010 means 10 (which is the same as +10)
1011 means 11 (which is the same as +11)
1100 means 12 (which is the same as +12)
1101 means 13 (which is the same as +13)
1110 means 14 (which is the same as +14)
1111 means 15 (which is the same as +15)

Conclusion: We can represent 16 different integers but all of them are positive.
How the 16 possible signed bit patterns are interpreted:
0000 means 0
0001 means 1 (which is the same as +1)
0010 means 2 (which is the same as +2)
0011 means 3 (which is the same as +3)
0100 means 4 (which is the same as +4)
0101 means 5 (which is the same as +5)
0110 means 6 (which is the same as +6)
0111 means 7 (which is the same as +7)
1000 means -8
1001 means -7
1010 means -6
1011 means -5
1100 means -4
1101 means -3
1110 means -2
1111 means -1

Conclusion: We can represent 8 different non-negative integers and 8 different negative integers.
Notice that the unsigned bit patterns don't really represent unsigned numbers. Each bit pattern in both sets represents an integer, and integers by nature always have a sign. People tend to gloss over the distinction.
There was more involved then I thought. This makes it totally clear what is happening.

Thanks guys. I can remember my teacher covering that in my Pascal class a couple years back.
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote
Old Jan 5, 2013, 01:39 PM   #9
Sydde
macrumors 68000
 
Sydde's Avatar
 
Join Date: Aug 2009
The simple mathematical logic of signed numbers is:
if a + b = 0
then a = -b
and
b = -a
If you assign a negative number to an int, then assign the value of that int to an unsigned int, you end up with an integer value that is very large, because all the assignment does is copy the bits over to the other field. If you then reverse the assignment, you get the negative number back. If you assign a negative number to a SInt64 (signed 64 bit value), then assign that to a UInt32 (unsigned 32 bit value), then reverse the assignment, the 64 will have the same value as the unsigned 32. This could be important to know in certain circumstances, but most of the time it will not affect program behavior (because most of the time, you will not do stuff like this).
__________________
You got to be a spirit. You can't be no ghost.
Sydde is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Quick Silly Question pcubed18 iPhone 11 Mar 20, 2014 09:27 PM
Silly question.... JohnGreenberg Mac mini 3 Jan 21, 2014 12:43 AM
Silly Power Off Question danielowenuk iPhone 11 Sep 18, 2013 04:39 PM
REALLY silly question imac wannabe Digital Photography 5 Apr 14, 2013 11:12 AM
iPhone: silly question but, can you sync while being jb, dannyhex Jailbreaks and iOS Hacks 5 Mar 14, 2013 01:43 AM

Forum Jump

All times are GMT -5. The time now is 09:02 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC