The "99" is ambiguous; it's an int, but it could equally well be converted to a char or to a short; because there's no way to decide, it's an error. All you need to do is apply a cast -- i.e., go((char) 99) or go((short) 99) . This tells Java which method you meant.
I have a doubt in implicit casting when i working on the above coding. char(16 unsigned ) can implicitly convert to Int,long,float,double. but Short<------char Ex short s=100; char c; s=c;//-------loss of precision error.
Is my understanding correct.Why i am asking this doubt,because both are 16 bits.
author and iconoclast
Originally posted by koh khai huat: What does the Signed and The Unsigned means???
Both char and short are sixteen bits, but the bits in a char are used to represent the numbers from 0 to 65535, while those in a short represent -32768 to +32767 . Therefore, chars can take on many values that char cannot, and vice-versa.
May I ask what is the meaning of Short is signed, and char is unsigned. What does the Signed and The Unsigned means???
you can think about the Singed and Unsigned in this way also. these are normal binary computational concepts. Here both short and char takes 2 bytes means 16 bits. In those 16 bits the short will use only 15 bits to represent the original magnitude of the number and the remaing bit to store the sign, 1 for negative and 0 for positive so it will accomdate 2^15 only. That is
<SingBit><0000 0000 0000 000> to <SingBit><1111 1111 1111 111>
But the char will use the whole 16 bits for magnitude means it will accomadte 2^16. That is <0000 0000 0000 0000> to <1111 1111 1111 1111>
These all must be instructed to host system how to treat them.
In those 16 bits the short will use only 15 bits to represent the original magnitude of the number and the remaing bit to store the sign, 1 for negative and 0 for positive so it will accomdate 2^15 only.
I am afraid you are mistaken there.
Java does not use that method of integer arithmetic, which is called sign and magnitude (S&M). An S&M integer in 16 bits runs from minus32767 (-2^15 + 1) to minus0, AND from 0 to 32767, so it has two values of zero, and a total range one less than -32768 to +32767, as Ernest Friedmann-Hill correctly quotes.
Java uses the two's complement format, where the bits from 0 to 15 (reading right to left, remember), represent
and minus32768, respectively.
This is a gross simplification of the two's complement format, but it will work.
The two's complement format has at least these four advantages over S&M:
It is monotonic: each binary pattern represents a number one different from its neighbours.
It uses the whole of the available range, because there is no duplication
An adding circuit can add complement numbers very easily, and subtract them by entering a single bit representing "minus"
Nobody cracks bad jokes about its acronym
I found a nice article about two's complement [url=http://en.wikipedia.org/wiki/Two's_complement]in Wikipedia, [/url]if it is any use to you.