Question for Uint, Sint.
Well, after some months of working with Uints and Sints, I decided to actualy understand what it means/does. I guessed it meant all this time unsigned int and signed int.. though, I still don't really understand the number 16, 32 or 8 given at the end. Anways, what exactly is the difference between Uint, Sint and unsigned int, signed int? Is it c only variable types? I'm only a c++ programmer, so I don't know too much into c specific code (if there is any) as I should.
|
Are you talking about the SDL integer types? The difference between an Uint32 (which is an unsigned 32-bit integer type, note the 32's) and a unsigned int is that a Uint32 is guaranteed to be 32 bits, but an unsigned int is only guaranteed at least the size of a character. This means it can be 8, 16, 32, 64 bits. int is generally considered the native integer type, or the type that the computer best processes. An 8-bit computer has an 8-bit int, a 16-bit computer has a 16-bit int, a 32-bit computer has a 32-bit int, a 64-bit computer has a 64 bit int, and a 128-bit computer would have a 128-bit int if one actually exists. A major thing to note is that the guaranteed types do not come with the language itself (not counting stdint.h).
|
The difference between signed and unsigned ints is????? the sign lol couldn't resist.
In signed ints one bit is reserved for the sign whilst in unsigned int this bit can be used for the number which it contains and therefore has a bigger range from zero to ... The numbers at the end are the number of bits they use, 8(char) 16(short etc) 32(32 int, float) 64(64 bit int double). |
Yeah, dmail is right: Uint and Sint are unsigned and signed ints (respectively). The difference is only in how the binary values are interpreted. And like tuxdev mentioned, the 8, 16, 32, etc., refer to the size (i.e. number of bits) used to represent an integer.
An 8-bit integer has two sets of possible values (depending on whether it's signed or unsigned): signed: -128 to +127 unsigned: 0 to +255 16-bit integer: signed: -32,768 to +32,767 unsigned: 0 to +65,536 ... and so on for 32-bit, 64-bit, etc.... (and just for trivia, I've worked with 256-bit embedded PowerPC processors. So there are definitely processors out there to handle monster-size ints) Quote:
Using a bit to represent the signed status of a number creates a "useless" overlap for value 0--a negative 0 and a positive 0. There's no need for that distinction, so twos-complement avoids that overlap by doing some bit-wise manipulation of numbers to translate between positive and negative values. By avoiding the 0-value overlap, there's a net gain of one other "useful" value. That's why the negative half of the number ranges quoted above have one more value than the positive ranges (unless you count 0 as a positive value). In all honesty, twos-complement comes pretty darn close to a sign-based-on-a-bit method, but it is different. |
Quote:
|
Quote:
Quote:
16 bit : int(16) long(32) 32bit: : int(32) long(32) 64bit : int(32) long(64) <-- see this |
All times are GMT -5. The time now is 06:08 AM. |