Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unsigned Variables

 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know what is unsigned int & unsigned long?
Also what long variable and short variable
Thanks
Angela
 
Junilu Lacar
Bartender
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Signed numbers use the leftmost bit to represent the sign and the remaining bits to represent the magnitude. Unsigned numbers use all the bits to represent the magnitude of the number.
long and short just indicate the size (number of bits) of the bit pattern used to represent a number. long has more bits (64)while short has fewer bits (16).
Java primitive integral data types are all signed with the exception of char (for which a sign has no meaning anyway).

[This message has been edited by JUNILU LACAR (edited June 22, 2001).]
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give me one example please?
Thanks
Angela
Originally posted by JUNILU LACAR:
Signed numbers use the leftmost bit to represent the sign and the remaining bits to represent the magnitude. Unsigned numbers use all the bits to represent the magnitude of the number.
long and short just indicate the size (number of bits) of the bit pattern used to represent a number. long has more bits (64)while short has fewer bits (16).
Java primitive integral data types are all signed with the exception of char (for which a sign has no meaning anyway).
[This message has been edited by JUNILU LACAR (edited June 22, 2001).]

 
Junilu Lacar
Bartender
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the campfire story http://www.javaranch.com/campfire/StoryBits.jsp
Angela, the Internet is chock-full of articles that I'm sure could explain the basics of bits and bytes better than anyone could in a single post. Bring up your favorite search engine--mine is http://www.google.com --and type in "bits and bytes" and you should come up with more than enough information. Google has a link to just the article you need in the very first page it lists. Sorry if this seems curt but I think that sometimes folks just have to learn how to help themselves.
Best regards,
Junilu
 
Bob Graffagnino
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
short i = 10;
long j = 10;
They both represent numbers. The difference is the amount of space they take up in memory. Consider the binary form of these numbers:
i = 00000000 00001010 (16 bits)
j = 00000000 00000000 00000000 00001010 (64 bits)
 
Mikael Jonasson
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference between a signed and an unsigned version of a variable is wether they allow negatives or not.
a signed byte for instans has the range between -128 and 127, while the unsigned version of it has the range between 0 and 255.
Making a variable unsigned means that the entire variable (all it's bits) are used for positive values.
ok?
/Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic