如何在 Eclipse 监视窗口中查看整数的不同表示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2754669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:42:25  来源:igfitidea点击:

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

javaeclipsedebugging

提问by jcartano

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

我想在调试时在 Eclipse 的监视窗口中查看整数的二进制(或十六进制)表示。我该怎么做呢?

回答by Joshua McKinnon

You can do this from Window->Preferences.

您可以从 Window->Preferences 执行此操作。

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

对于基元,浏览到 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

对于对象(Integer、Long 等),浏览到 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)

对于您关心的每种类型,创建一个详细信息格式化程序,以您喜欢的方式格式化值。对于 java.lang.Integer,您可以使用详细信息格式化程序: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.

确保您的详细信息格式化程序已启用,当您从“变量”视图中选择一个变量时,您应该会在“详细信息”区域中看到十六进制表示。

回答by aioobe

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

您最好的选择可能是打开表达式视图(窗口 -> 显示视图 -> 表达式),右键单击,选择“添加监视表达式”,然后输入Integer.toBinaryString(yourInt)Integer.toHexString(yourInt),然后单击确定。