简体   繁体   English

Java Pad地址到64位

[英]Java pad address to 64-bit

I'm currently dealing with some memory addresses that I need to pad to a full 64-bit in length. 我目前正在处理一些需要填充到完整64位长度的内存地址。 As an example: 举个例子:

0x7ffe0 - needs to be padded to: 0x000000007ffe0000

Essentially each value needs to be padding out to 16 digits with the zeros in the right places. 本质上,每个值都需要填充到16位数字,并在正确的位置添加零。

I know String.format will probably do it, but I'm not sure if DecimalFormat is quicker, or the better way to do this. 我知道String.format可能会这样做,但是我不确定DecimalFormat是更快还是更好的方法。

Any advice would be greatly appreciated. 任何建议将不胜感激。

Thanks 谢谢

UPDATE UPDATE

This is how the memory information is stored within the file: 这是内存信息在文件中的存储方式:

在此处输入图片说明

Essentially the first 8 bytes are the start of a range, and the last 8 are where the range ends. 本质上,前8个字节是范围的开始,而后8个字节是范围的结束位置。

Another program I have access to is showing me the full 64-bit padded address, so I'm not entirely sure how it is performing the padding. 我可以访问的另一个程序向我显示了完整的64位填充地址,因此我不确定该如何执行填充。

try this 尝试这个

String s = String.format("0x%016x", 0x7ffe0);

DecimalFormat works only with decimals not hexadecimals DecimalFormat仅适用于小数而不是十六进制

试试这样的事情

    System.out.printf("0x%016x", 0x7ffe0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM