• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Integral types -- MG Exam 3 Q 25

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello James,
Just to add one point.

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
What do experts have to say about this.
------------------
Regards,
Raj.
-------------------------
Afforts should be Appriciated.
-------------------------
 
James Baud
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic