# Integral types -- MG Exam 3 Q 25

shree vijay
Ranch Hand
Posts: 208
Question 25)
Which of the following statements are true?
1) The following statement will produce a result of 1. System.out.println( -1 >>>2);
2) Performing an unsigned left shift (<<<) on a negative number will always produce a negative number result <br /> 3) The following statement will produce a result of zero, System.out.println(1 >>1); <br /> 4) All the integer primitives in java are signed numbers <br /> <br /> Answer to Question 25) <br /> Objective 5.1)<br /> 3) The following statement will produce a result of zero, System.out.println(1 >>1);
Although you might not know the exact result of the operation -1 >>> 2 a knowledge of the way the bits will be shifted will tell you that the result is not plus 1. (The result is more like 1073741823 ) There is no such Java operator as the unsigned left shift. Although it is normally used for storing characters rather than numbers the char Java primitive is actually an unsigned integer type.

now , should i include char in integral types? I remember studying that numeric types are divided into integral types and char -- integral are(byte,short,int,long)

------------------
Regards,
Shree

James Baud
Ranch Hand
Posts: 60
shree vijay,
I think what was meant here is that the bit-representation of char is that of an unsigned integer whose range falls between 0x0 to 0xffff, or 0 to 2**16. The key here is the whole 16 bits. For signed integers (byte, short, int, char) the bit spectrum for the integer value has to give up one bit to denote the sign. Primitive type short, for example, can only have a postive max value of 2**15 - 1.
Hope this helped.
------------------
~James Baud
Talk, does not cook rice. - Chinese Proverb

Rajpal Kandhari
Ranch Hand
Posts: 126
Hello James,

The char type is integral but unsigned.
All the numerical primitive types(thatis, all except boolean and char) are signed.
James,
The range of a variable of type char is from 0 to 2power16-1.
Regards
Raj.

James Baud
Ranch Hand
Posts: 60
Rajpal Kandhari:

The char type is integral but unsigned.

Yes, the type is integral, but at the bit-level you can think of char as an unsigned integer with a width of 16 bits.

The range of a variable of type char is from 0 to 2power16-1.

The char datatype encompasses all the 65536(2power16) characters of the Unicode character set as 16-bit values. - Khalid A. Mughal, A Programmer's Guide to Java Certification Sec 2.5, p. 31
------------------
~James Baud
Talk, does not cook rice. - Chinese Proverb

Rajpal Kandhari
Ranch Hand
Posts: 126
Hello James,
RHE book says on page-9 "The range of a variable of type char is from 0 through 2(power)16-1."
Now which author is correct.
------------------
Regards,
Raj.
-------------------------
Afforts should be Appriciated.
-------------------------

James Baud
Ranch Hand
Posts: 60
Hi Raj,
Both authors are correct. If we analyze the wordings carefully, all 65536(2power16)[KAM] actually means that, w/ zero offset, the min_value = 0 and max_value = 65535(2power16-1)[RHE].
0xffff equals 65535(2power16-1) not 2**16 as I previously announced. My apologies.
------------------
~James Baud
Talk, does not cook rice. - Chinese Proverb