Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

SIGNED AND UNSIGNED

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI everybody..
I have a silly doubt.. All integral literals(byte, short, int and char) r signed.....
Can somebody explain in simple words the difference between signed and unsigned literals.
Thanks in advance..
shalini
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i suppose char is not signed its unsigned..
signed means if the MSB is 1( in bit representation) then the number is negetive.. else positive..
suppose for bytes
if this is signed
11111111 -> -1
if unsigned ( but java dosent support unsigned byte)
11111111 -> 255
HTH
anil
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not fair to say that all interger types in java are signed. It is not true. JLS says that 'char' is unsigned and it is part of integral type. All numeric data types are SIGNED.
char is the only UNSIGNED integral type.
The following example may clear the confusion.
int i=-1; //compiles
byte i=-1;//compiles.
char i=1;//compiles
char i=-1;//Explicit cast needed to convert int to char,because char type is UNSIGNED
char i=(char)-1;//compiles fine.
Correct me if I'm wrong.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic