This week's book giveaway is in the Jobs Discussion forum.We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!

# doubt on java fundamental mock exam

R .sourav nayak
Ranch Hand

Joined: May 14, 2006
Posts: 67
hi,
the following mock question is from DanC mock exam site and could some explain me how to calculate the output of this type of questions

class JJF3 {
public static void main(String args[]) {
System.out.print(Integer.toBinaryString(Byte.MAX_VALUE)+",");
System.out.print(Integer.toOctalString(Byte.MAX_VALUE)+",");
System.out.print(Integer.toString(Byte.MAX_VALUE)+",");
System.out.print(Integer.toHexString(Byte.MAX_VALUE));
}}
the result is
. Prints: 1111111,177,127,7f

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Conversions from binary to octal and binary to hexadecimal and vice versa are pretty simple.

For example, if you have a binary string and you want to convert it to

1. octal, then left pad the String with 0 until the number of digits is a multiple of 3. Then divide the String into groups of 3 and convert each to its octal equivalent (000 = 0, 001 = 1, 010=2, 011=3, 100=4, 101=5, 110=6, 111=7).

2. hexadecimal, then left pad the String with 0 until the number of digits is a multiple of 4. Then divide the String into groups of 4 and convert each to its hexadecimal equivalent (0000 = 0, 0001 = 1, 0010 = 2, 0011 = 3, 0100 = 4, 0101 = 5, 0110 = 6, 0111 = 7, 1000 = 8, 1001 = 9, 1010 = A, 1011 = B, 1100 = C, 1101 = D, 1110 = E, 1111 = F).

For the reverse, its even easier.

To convert from

1. octal to binary, replace each digit with its three digit binary equivent.

2. hexadecimal to binary, replace each digit with its four digit binary equivalent.
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
A byte is an 8 bit signed value. The left most bit is the sign bit. The sign bit is set to zero for positive numbers and is set to one for negative numbers. The most positive byte value is represented as a sign bit that is set to zero and all of the other bits set to one. The Integer.toBinaryString method does not print leading zeros; so only seven bits are printed. An eight bit binary value is represented as three octal digits. The first of the three digits represents the left most two bits of the binary value. In this case, the left most two bits are zero and one. The second octal digit represents the next three bits of the binary value. The last of the octal digits represents the right most three bits of binary value. Note that the Integer.toOctalString method does not print a leading zero as is required for an octal literal value. An eight bit binary value is represented as two hexadecimal digits. The left hex digit represents the left most four bits of the binary value. The right hex digit represents the right most four bits of the binary value.

So the output 1111111,177,127,7f

A bend in the road is not the end of the road ... unless you fail to make the turn.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8898

5
Hi Guys,

If this is in scope at all, it's just ever-so-barely in scope, and then only for the 1.4 exam.

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
R .sourav nayak
Ranch Hand

Joined: May 14, 2006
Posts: 67
hi,
i am writing 1.4 on April, so i have to go over all these topics

I agree. Here's the link: http://aspose.com/file-tools

subject: doubt on java fundamental mock exam