Tutorial :How do I view different representations of integers in the Eclipse watch window?



Question:

I would like to view binary (or hex) representations of integers in my watch window in Eclipse when debugging. How do I do this?


Solution:1

You can do this from Window->Preferences.

For primitives, browse to Java->Debug->Primitive Display Options

Here there is a checkbox for 'Display Hexadecimal values'. Check this, and you will see both decimal & hexadecimal representations for primitives in the 'value' column under Variables view when debugging.

For objects (Integer, Long, etc), browse to Java->Debug->Detail Formatters

For each type you care about, create a detail formatter that formats the value how you like. For java.lang.Integer, you could use the detail formatter: Integer.toHexString(this)

Make sure your detail formatter is enabled, and you should see the hexadecimal representation in the 'details' area when you select a variable from the Variables view.


Solution:2

Your best option is probably to open the Expressions view (Window -> Show View -> Expressions), right click, choose "Add Watch Expression" and then enter Integer.toBinaryString(yourInt) or Integer.toHexString(yourInt), and click ok.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »