File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Unsigned Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unsigned Variables" Watch "Unsigned Variables" New topic
Author

Unsigned Variables

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
I want to know what is unsigned int & unsigned long?
Also what long variable and short variable
Thanks
Angela
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

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 - [How to Ask Questions] [How to Answer Questions]
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
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

Joined: Feb 26, 2001
Posts: 4419
    
    5

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

Joined: May 30, 2001
Posts: 81
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

Joined: May 16, 2001
Posts: 158
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
 
Don't get me started about those stupid light bulbs.
 
subject: Unsigned Variables
 
Similar Threads
Printing out Ascii charactors
BigInteger to byte array of size 8 bytes (Unsigned long) in Java
is char unsigned 16 bit?
How to read a C++-struct-constructed Binary Data
Reverse of Long.toHexString()