Original Post
whats the diff between a signed and an unsigned variable, what advantages/disadvanteges, uses and when should i use them ??
thanx, silvermace
quote:
Original post by Alimonster
Signed numbers store their sign by using a bit of the variable to store positive or negative - if the bit is 1 then the value is negative, otherwise it's positive.
If you say 'that' is the sign bit, then:
32767 = 0111 1111 1111 1111
-32767 = 1111 1111 1111 1111
what about -32768?? It doesn't make sense to have -0 as -32768 if you says 'that' is the sign bit.
-------------------------------------------
It should be this way, eg. short /_int16 :
1: 0000 0000 0000 0001
...
32767: 0111 1111 1111 1111
-32768: 1000 0000 0000 0000
-32767: 1000 0000 0000 0001
...
-1: 1111 1111 1111 1111
--------------------------------------------
why not -1 = 1000 0000 0000 0001 ?
why not -0 = 1000 0000 0000 0000 (heheheh... )
quote:
Original post by DerekSaw
Just search for 2''s complement... then you should know.![]()
quote:
Original post by Alimonster
Way ahead of you, dude.
quote:
Use unsigned numbers where possible. They''re quicker for the CPU to deal with and make more sense in some uses (for example, to store sizes and counts).
quote:
In many cases, the data stored in integer variables determines whether a signed or an unsigned integer type is appropriate. For example, to record the weight of a person in pounds, no negative numbers are required, so an unsigned type is
appropriate. However, recording temperatures in degrees Celsius may require both positive and negative numbers, so a signed type is needed.
Where there is a choice of using either a signed or an unsigned type, take into consideration that certain operations are faster with unsigned types while others are faster for signed types.
Integer-to-floating-point conversion using integers larger than 16 bits is faster with signed types
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more