如何在 Eclipse Java 调试器中将字节数组显示为十六进制字节或无符号十进制数的数组?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3939461/
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-08-14 07:14:11  来源:igfitidea点击:

How do I display a byte array as an array of hex bytes or unsigned decimal numbers in the Eclipse Java debugger?

javaeclipsetypesdebugging

提问by Daryl Spitzer

I want to view a byte array in the Eclipse (Helios Release, build id: 20100617-1415) Java debugger as an array of hex bytes (2 digits each) or unsigned decimal numbers? Is that possible? How?

我想在 Eclipse (Helios Release, build id: 20100617-1415) Java 调试器中查看字节数组作为十六进制字节数组(每个 2 位数)或无符号十进制数?那可能吗?如何?

For example, I want to display this:

例如,我想显示这个:

alt text

替代文字

...as: 0, 48, 71, 22, 139, 166, ...

...如:0, 48, 71, 22, 139, 166, ...

...or as: 0x00, 0x30, 0x47, 0x16, 0x8B, 0xA6, ...

...或如:0x00, 0x30, 0x47, 0x16, 0x8B, 0xA6, ...

(This is a similar question to "How do I display a byte array as a char array in the Eclipse Java debugger?".)

(这是一个类似于“如何在 Eclipse Java 调试器中将字节数组显示为字符数组?”的问题。)

采纳答案by pinichi

Not exact what you want but as I know in DEBUG MODE, there is an option for primitive Types (int, long,...).

不完全是你想要的,但正如我在调试模式中所知道的那样,原始类型有一个选项(int,long,...)。

 Switch to Debug perspective.
 In the Variables view click the "menu" item (triangle item before minimize) and select "Java Primitives...".
 In the Dialog you can choose between Hex view, Ascii view and unsigned (for byte).

 切换到调试透视图。
 在变量视图中单击“菜单”项(最小化前的三角形项)并选择“Java Primitives...”。
 在对话框中,您可以在十六进制视图、ASCII 视图和无符号(字节)之间进行选择。

Found this, maybe help: Inside the Memory View

找到了这个,也许有帮助:在内存视图中

On 3.7 (and maybe earlier), go into preferences, type "primitive display" in the filtering area, and choose to display hex values.

在 3.7(也许更早版本)上,进入首选项,在过滤区域中输入“原始显示”,然后选择显示十六进制值。

回答by Thomas Keene

Updated answer in Eclipse Kepler 4.3:

Eclipse Kepler 4.3 中的更新答案:

In the Debug perspective, the Variables tab will have View Menu (a downward triangle), Minimize (a line), and Maximize (a window) icons in the upper-right corner. Click on View Menu > Java > Java Preferences... to bring up a menu. In this menu select Java > Debug > Primitive Display Options. Check "Display hexadecimal values" and then click OK. You should now see hex values in brackets in the Variables tab.

在 Debug 透视图中,Variables 选项卡的右上角将有 View Menu(一个向下的三角形)、Minimize(一条线)和 Maximize(一个窗口)图标。单击“查看菜单”>“Java”>“Java 首选项...”以显示一个菜单。在这个菜单中选择 Java > Debug > Primitive Display Options。选中“显示十六进制值”,然后单击“确定”。您现在应该在“变量”选项卡中的括号中看到十六进制值。

回答by ykaganovich

You can add a Watch Expression:

您可以添加监视表达式:

   StringBuilder sb = new StringBuilder();
    for(byte b: buf) {
      sb.append(String.format("%02x, ", b & 0xff));
    }
    sb.setLength(sb.length() - 2);
    return "[" + sb + "]";

回答by gvlasov

In IntelliJ IDEA 14, displaying of hex values in arrays in debugger can be enabled with Settings → Debugger → Data Views → Java → Show hex values for primitives.

在 IntelliJ IDEA 14 中,可以通过Settings → Debugger → Data Views → Java → Show hex values for primes启用在调试器中的数组中显示十六进制值

回答by Ujjwal Roy

For eclipse neon IDE

用于日食霓虹 IDE

Displaying values in hexadecimal format

以十六进制格式显示值

goto Windows-> Preferences-> Java-> Debug-> Primitive Display option-> Display Hexadecimal values(byte,short,char,int,long)

转到Windows->首选项-> Java->调试->原始显示选项-> 显示十六进制值(字节、短、字符、整数、长)

enable the option and press OK

启用该选项并按OK

NOTE: This works in debug mode

注意:这在调试模式下有效