|
|
#1 |
|
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 |
|
|
|
0
|
|
|
#2 |
|
Unsigned integers don't store any information about the sign of the number.
__________________
Of crimes---none is greater than having things that one desires; Of disasters---none is greater than not knowing when one has enough. Of defects---none brings more sorrow than the desire to attain. |
|
|
|
0
|
|
|
#3 | |
|
Quote:
So it is what I thought. Thanks for confirming it.
__________________
I know more than yesterday. Lars |
||
|
|
0
|
|
|
#4 |
|
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.
|
|
|
|
0
|
|
|
#5 |
|
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. |
|
|
|
0
|
|
|
#6 |
|
Sign being a property of a number, either positive or negative.
__________________
Of crimes---none is greater than having things that one desires; Of disasters---none is greater than not knowing when one has enough. Of defects---none brings more sorrow than the desire to attain. |
|
|
|
0
|
|
|
#7 |
|
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 0How the 16 possible signed bit patterns are interpreted: 0000 means 0Notice 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. |
|
|
|
0
|
|
|
#8 | |
|
Quote:
Thanks guys. I can remember my teacher covering that in my Pascal class a couple years back.
__________________
I know more than yesterday. Lars |
||
|
|
0
|
|
|
#9 |
|
The simple mathematical logic of signed numbers is:
if a + b = 0If 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).
__________________
Mr. Paul, sir, I thought you should be advised, there seems to be a zombie tribble clinging to your head, for it is scarfing your brain
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 01:18 AM.







I support the
Linear Mode
