• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Q. >>>

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did an exam on the www.certification4career.com, but I've got some doubts about the answers given. Can someone help me with this?
Mock Exam

Answer. B, and C.
Shouldn't the answer also be A, because the negative bit is not kept?
For example,

[ April 28, 2003: Message edited by: Karin Paola Illuminate ]
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to be right in all your 'doubts'. I would be interested in knowing what the certification.com guys have to say.
Rattan
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps Cat and Mouse Game with Bits will help you.
 
author
Posts: 9000
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karin -
>>> almost always does what you'd think. Try using multiples of 32 when >>>'ing an int, or multiples of 64 when >>>'ing a long.
-Bert
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say only C is correct, because 0 is not a positive number.
 
Bert Bates
author
Posts: 9000
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marlene -
OK I'll bite ... 0's sign bit would indicate that Java considers it to be 'positive' so (he asks, putting his foot into it :roll: ), where does it say that Java doesn't consider an integer type 0 to be positive?
 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bert,
you mean something like this?

This will result in -1 (because of -1 >>> 0).
I've got it. It will not always result in a positive number.
Thanks.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bert,
Is 0 a positive integer?
I had to do some research, because it did not occur to me to question my assumption. I wasn�t sure what I would find. I looked through the JLS and I also looked at a few API�s - Math, BigInteger and Comparable. Here are the most convincing statements that I came across.
JLS 3.10.1 Integer Literals
A decimal numeral is either the single ASCII character 0, representing the integer zero, or consists of an ASCII digit from 1 to 9, optionally followed by one or more ASCII digits from 0 to 9, representing a positive integer
JLS 3.10.1 Integer Literals
A hexadecimal numeral consists of the leading ASCII characters 0x or 0X followed by one or more ASCII hexadecimal digits and can represent a positive, zero, or negative integer.
10.7 Array Members
The public final field length, which contains the number of components of the array (length may be positive or zero)
Java API for Comparable, compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Marlene
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karin,
Good thinking! I forgot about a shift of length 0. �1 >>> 0 is �1.
I was thinking about something else, which is what I assume Bert is referring to. 1 >>> 1 is 0. 0 is not positive.
 
What's a year in metric? Do you know this metric stuff tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic