LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-31-2006, 07:39 PM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
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.
 
Old 08-31-2006, 07:57 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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).
 
Old 08-31-2006, 07:57 PM   #3
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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).
 
Old 08-31-2006, 08:27 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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:
Originally Posted by dmail
In signed ints one bit is reserved for the sign
That is one way to do it, but integers are typically stored in twos-complement form. For anyone not familiar with twos-complement, search Google and you should find tons, but the basics are...

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.

Last edited by Dark_Helmet; 08-31-2006 at 08:29 PM.
 
Old 08-31-2006, 08:32 PM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
In signed ints one bit is reserved for the sign
Silly me, I was thinking about floats, don't ask why lol.
 
Old 08-31-2006, 11:13 PM   #6
jineshkj
Member
 
Registered: Apr 2006
Distribution: Fedora
Posts: 33

Rep: Reputation: 15
Quote:
Originally Posted by tuxdev
int is generally considered the native integer type, or the type that the computer best processes
Yes. Thats what is said in C language specifications

Quote:
Originally Posted by tuxdev
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.
I don't think you are completely correct. See the facts below:

16 bit : int(16) long(32)
32bit: : int(32) long(32)
64bit : int(32) long(64) <-- see this
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
expected primary expression before... Uint character question. RHLinuxGUY Programming 3 05-12-2006 12:08 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
samba smb.config question (quick question) TheDOGG Linux - Networking 1 03-02-2004 07:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration