• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why does core java doesnt have unsigned int??

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why does core java doesnt have unsigned int???


and why whenever an unsigned varible assigned a negative number in C++,doesnt create an errorr?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ???
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic