File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Long Hexadecimal numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Long Hexadecimal numbers" Watch "Long Hexadecimal numbers" New topic
Author

Long Hexadecimal numbers

M Bhalli
Greenhorn

Joined: Oct 09, 2003
Posts: 9
How can we approach this kind of question in java exam? we have to convert Hexadecimal numbers into binary and then try to find out the results or there is any other way we can quickly solve this kind of problem?
Thanks
class EBH019 {
public static void main (String args[]) {
int i1 = 0xffffffff, i2 = i1 << 1;
int i3 = i1 >> 1, i4 = i1 >>> 1;
System.out.print(Integer.toHexString(i2) + ",");
System.out.print(Integer.toHexString(i3) + ",");
System.out.print(Integer.toHexString(i4));
}}
What is the result of attempting to compile and run the program?
a. Prints: ffffffff,ffffffff,ffffffff
b. Prints: ffffffff,ffffffff,7fffffff
c. Prints: ffffffff,7fffffff,ffffffff
d. Prints: ffffffff,7ffffffe,7ffffffe
e. Prints: fffffffe,ffffffff,ffffffff
f. Prints: fffffffe,ffffffff,7fffffff
g. Prints: fffffffe,7fffffff,ffffffff
h. Prints: fffffffe,7fffffff,7fffffff
i. Run-time error
j. Compile-time error
k. None of the above
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

http://www.permadi.com/tutorial/numHexToDec/


Groovy
M Bhalli
Greenhorn

Joined: Oct 09, 2003
Posts: 9
Thank You Pradeep,
but my question is, "do we have to convert these numbers to binary and then we can solve this kind of questions in exam or is there just a simple way of solving these kind of question because it takes a longer time to convert numbers into binary, Thanks
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Welcome to the Ranch M Bhalli.
For the exam converting from hex to bin is necessary. In this example the answers are in hex, thus you do not need to convert.


SCJP2. Please Indent your code using UBB Code
M Bhalli
Greenhorn

Joined: Oct 09, 2003
Posts: 9
Thank you Jose,
i have one more question, That ~(bitwise inversion operator) it reverse all the bits of interger variable. What i m thinking that if int x=3;then 3 is being stored in x using 32 bits like 00000000000000000000011 (32bits), and when u apply ~x then 11 should convert to 00 and rest of all zeros should convert into 1's is it right, but when i compile the code the result is quite different. Please tell me what is going on here.
Thanks a lot!!
 
 
subject: Long Hexadecimal numbers
 
Similar Threads
Reg Shift operators
using shift operators
mock doubt(DAN)
Number formts and ranges
shift operators