I would like to view binary (or hex) representations of integers in my watch window in Eclipse when debugging. How do I do this?
2 Answers
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.

- 24,489
- 11
- 57
- 63
-
1Doesn't seem to work for arrays. I'm trying to display an int[] as hex, but changing the primitives doesn't change it and I don't know what class to specify for eclipse to translate. – mjaggard Nov 26 '12 at 09:46
-
1It doesn't work for an unexpanded array in the Variables view, but when expanded it should still show the hex values of the array elements. [screenshot](http://i926.photobucket.com/albums/ad105/onelin/java-variables-int-array.png). I can't think of a way you'd specify an array under detail formatters either... – Joshua McKinnon Nov 27 '12 at 03:13
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.

- 84,978
- 11
- 107
- 151

- 413,195
- 112
- 811
- 826