Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以二进制格式在Java字符数组中打印_Java_Binary_System.out - Fatal编程技术网

以二进制格式在Java字符数组中打印

以二进制格式在Java字符数组中打印,java,binary,system.out,Java,Binary,System.out,我有一个字符数组 static char[] myArray ={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00, 0x00, 0x20, 0xf0, 0x

我有一个字符数组

static char[] myArray  ={   
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20,
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00,
0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0x08,
};

如何将其打印为8位二进制文件

对每个项目使用
toBinaryString

for (int i = 0; i < myArray.length; i++) {
        String b = Integer.toBinaryString(myArray[i]);

        if (b.length() < 8) {
            b = "000000000".substring(0, 8 - b.length()).concat(b);
        } else {
            b = b.substring(b.length() - 8);
        }

        System.out.print(b + " ");
 }
for(int i=0;i
输出

00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000 111110001001001000 01001000 01001000 1011000


对每个项目使用
toBinaryString

for (int i = 0; i < myArray.length; i++) {
        String b = Integer.toBinaryString(myArray[i]);

        if (b.length() < 8) {
            b = "000000000".substring(0, 8 - b.length()).concat(b);
        } else {
            b = b.substring(b.length() - 8);
        }

        System.out.print(b + " ");
 }
for(int i=0;i
输出

00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000 111110001001001000 01001000 01001000 1011000


如果输出为
0000000000000000 F848484…

    for(char c : myArray) {
        System.out.printf("%02x", (int)c);
    }

如果输出为
0000000000000000 F848484…

    for(char c : myArray) {
        System.out.printf("%02x", (int)c);
    }

看一看:打印单个字符:添加循环很简单。它与那些链接不同,转换为二进制是相同的,但8位部分不同。看一看:打印单个字符:添加循环很简单。它与那些链接不同,转换为二进制是相同的,但8位部分不是。这不会输出二进制;)这不会输出二进制文件;)