aspose file tools*
The moose likes Beginning Java and the fly likes why does core java doesnt have unsigned int?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why does core java doesnt have unsigned int??" Watch "why does core java doesnt have unsigned int??" New topic
Author

why does core java doesnt have unsigned int??

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

why does core java doesnt have unsigned int???


and why whenever an unsigned varible assigned a negative number in C++,doesnt create an errorr?


http://www.lifesbizzare.blogspot.com || OCJP:81%
Ryan Webb
Greenhorn

Joined: Dec 09, 2009
Posts: 28
no unsigned for primitives kinda suck huh?

in my opinion, this is for portability purposes...
unsigned types tend to have larger values than signed types
creators of java want to make sure whether on any platform you use java values have the same limit on primitives

More Info here


frustrated to learn c/c++/objective-c
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

i know this is a java forum but please do answer this qustion on c program


unsigned int a=-5;


when i tried to compile and run it it displayed -5


usigned int states that it has only positive value???
now what is going on here ???
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
You are obviously taking the bits of the signed number -5, which in 32 bits is 2^32 - 5. Since C isn't a type-safe language, it will take the same bit pattern as that and covert it to positive or negative numbers depending on whether you use the %u or %i flags to display it.Try that, remembering the scanf . . . %i will take 2147483647 (maximum value of int) for anything larger.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does core java doesnt have unsigned int??