best strategy to answer this question??

sabah ammar
Greenhorn
Posts: 23
hi pals,
can someone please tell me how can i use method of elimination for questions like this, because i believe i cant solve the whole of it during the exam, or if u ve got some other better way to have it done correct!! thank you.

public class Test{
public static void main(String args[]){
int i=oxFFFFFFF1;
int j=~i;
}}

which is decimal value of j at line 5?
A. 0
B.1
C.14
D.-15
E. compile error at line 3
F. compile error at line 4

Mike Gershman
Ranch Hand
Posts: 1272
Here is how I approach this problem.

11111111 11111111 11111111 11110001 in binary

~i means to replace every 0 bit with a 1 bit and replace every 1 bit with a 0 bit, so ~i is
00000000 00000000 00000000 00001110 in binary, which is 14 in decimal

If I can't do a bit manipulation problem quickly in my head, I do it in binary, not in hexadecimal.

David Harkness
Ranch Hand
Posts: 1646
Originally posted by sabah ammar:
3: int i=oxFFFFFFF1;
...
E. compile error at line 3
If that really is a lowercase o and not a leading 0 before the x, then the answer is E.

sabah ammar
Greenhorn
Posts: 23
mike thank you for the simple answer but it lead me to this one more question.can u please explain the method to convert hex - binary?

sabah ammar
Greenhorn
Posts: 23
sorry.. i just got misunderstood with the converstion, i...obviously know the hex-bin conversion.. thanks again.

Jay Pawar
Ranch Hand
Posts: 411
One more tip . If the question asked is in decimal form like this

then the value of k can be calculated as k = - ( j + 1 )

sabah ammar
Greenhorn
Posts: 23
this is something smart

ankur rathi
Ranch Hand
Posts: 3830
Jay ,
Have you ever prepared for MBA entrance ...

Jay Pawar
Ranch Hand
Posts: 411
Originally posted by rathi ji:
Jay ,
Have you ever prepared for MBA entrance ...

My dad wanted me to do that. not me BTW where are you in India?

ankur rathi
Ranch Hand
Posts: 3830
But you should go for that ...
I am in Pune .

Nicholas Cheung
Ranch Hand
Posts: 4982

My dad wanted me to do that

Might be this is a bit off topic, however, personally, I believe MBA is a must nowadays for entering into management level with a easier career path.

MBA did offer you a good chance to meet with different people from different companies. And if the MBA programme is highly recognized, it really helps you to build a "network" that benefits much in your career path as you might meet "powerful" guys.

Of course, you need to have experiences on how to manage people. As said all the time, getting a certificate with no experience means nothing at all.

Nick

Maciej Gulak
Greenhorn
Posts: 2
Hi Jay,

I think you wanted to type '-' instead of '+'.

For example, JLS says: "[...] note that, in all cases, ~x equals (-x)-1"

br,
Maciej