简体   繁体   English

此代码如何使该十六进制值?

[英]How this code makes that hex values?

can any one explain me "in details" how this code makes a .cfg file that is like the picture in the left? 任何人都可以“详细地”向我解释一下此代码如何生成类似于左图的.cfg文件吗? I wanna change it so that it becomes like the right one? 我想更改它,使其变得正确吗?

setLastFileInTNM(getTnmInstalledPath(), getLastPath());

private void setLastFileInTNM(String TNMConfigFilePath, String fileTobeSetInTNM) throws Exception {
    //fileTobeSetInTNM  += " ";
    File file = new File(TNMConfigFilePath);
    char[] dt = fileTobeSetInTNM.toCharArray();

    char[] data = readFile(file);

    int offset = 145;
    int length = fileTobeSetInTNM.length();

    int j = 0;
    for (int i = 145; i < offset + length; i++) {
        if (j == dt.length) {
            break;
        }
        data[i] = dt[j];
        j++;
    }
    data[offset + length] = (char) 0;//for seprating the rest
    writeToFile(data, file);
    readFile(file);
}

This code writes an address in the .cfg file. 此代码在.cfg文件中写入一个地址。 the picture below is comparing two .cfg file in notepad++. 下图比较了notepad ++中的两个.cfg文件。 The left one is made by the code above, I want to change the code so that the hex type becomes like the right picture. 左边的是上面的代码,我想更改代码以使十六进制类型变得像右边的图片。 how should i change the code? 我应该如何更改代码?
在此处输入图片说明

The text on the right says 右边的文字说

" D : \\ MDS 8 3 1 0 . hex " , while the text on the left says " D : \\ MDS 8 3 1 0 . hex " ,而左侧的文本显示

" D:\\MDS 8310.hex 1 0 . hex " . " D:\\MDS 8310.hex 1 0 . hex "

This suggests that the encoding of the data in the original file is 16-bit per character, leaving every second character as space, and on the left you just copy each character as a byte, thus getting the file name too condensed. 这表明原始文件中的数据编码为每个字符16位,第二个字符保留为空格,在左侧,您仅将每个字符复制为一个字节,从而使文件名过于紧凑。 If you want to do it in this low level style, just add line 如果要以这种低层样式进行操作,只需添加一行

data[++i] = 0x20; 

after line: 下一行:

data[i] = dt[j];

and increase the upper bound of the for loop to offset + length * 2 并将for循环的上限增加为offset + length * 2

I do not see why your file is modified also on the line 29 and on the line 6, but that may depend on the rest of your code. 我看不到为什么在第29行和第6行也修改了您的文件,但这可能取决于您其余的代码。

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

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