posted 14 years ago

Hi all!

Got this in a mock exam:

class JJF5 {

public static void main(String args[]) {

System.out.print(Integer.toHexString(Integer.MIN_VALUE)+",");

System.out.print(Integer.toHexString(Integer.MAX_VALUE));

}}

So the question is "how do you convert -2^31 to hexadecimal?" and I have to be missing some nice trick here cause I need a calculator to try and solve this. First of all, I know what the MIN and MAX values are but I haven't memorized the decimal representation. Should I know what 2^31 is for the exam??? Secondly, say I come up with 2147483648, how do I convert such a large number to hexadecimal?

The answer given in the mock exam is "Prints: 80000000,7fffffff" but there is no explanation. How do you get to that result?

If this question does require some large calculations, is it likely to get something similar in the real exam?

Thanks a lot!

Got this in a mock exam:

class JJF5 {

public static void main(String args[]) {

System.out.print(Integer.toHexString(Integer.MIN_VALUE)+",");

System.out.print(Integer.toHexString(Integer.MAX_VALUE));

}}

So the question is "how do you convert -2^31 to hexadecimal?" and I have to be missing some nice trick here cause I need a calculator to try and solve this. First of all, I know what the MIN and MAX values are but I haven't memorized the decimal representation. Should I know what 2^31 is for the exam??? Secondly, say I come up with 2147483648, how do I convert such a large number to hexadecimal?

The answer given in the mock exam is "Prints: 80000000,7fffffff" but there is no explanation. How do you get to that result?

If this question does require some large calculations, is it likely to get something similar in the real exam?

Thanks a lot!

posted 14 years ago

Hi Lionel,

As you know an int is a 32 bit signed value with left

most bit as the sign bit.

The sign bit is one for negative numbers and zero for

positive numbers.

Given the bit representation of MIN_VALUE and MAX_VALUE

by conversion you can find the HEX value.

MIN_VALUE 1000 0000 0000 0000 0000 0000 0000 0000

8 0 0 0 0 0 0 0

MIN_VALUE 0111 1111 1111 1111 1111 1111 1111 1111

7 F F F F F F F

Greetings,

Gian Franco Casula

As you know an int is a 32 bit signed value with left

most bit as the sign bit.

The sign bit is one for negative numbers and zero for

positive numbers.

Given the bit representation of MIN_VALUE and MAX_VALUE

by conversion you can find the HEX value.

MIN_VALUE 1000 0000 0000 0000 0000 0000 0000 0000

8 0 0 0 0 0 0 0

MIN_VALUE 0111 1111 1111 1111 1111 1111 1111 1111

7 F F F F F F F

Greetings,

Gian Franco Casula

"Eppur si muove!"

posted 14 years ago

Yo Mate,

Theres a brilliant site for studying for the java exam Gives you mock exams...explains the questions and answers....

you'll find everything to do with hex..otc...bin...there as well

heres the link

http://home.comcast.net/~danchisholm/index.html

Theres a brilliant site for studying for the java exam Gives you mock exams...explains the questions and answers....

you'll find everything to do with hex..otc...bin...there as well

heres the link

http://home.comcast.net/~danchisholm/index.html

gazman

It is sorta covered in the JavaRanch Style Guide. |