Java: 字节数组的长度好像是从二进制字符串转换过来的不对

Java: the length of the byte array seems to be wrong from converting a string of binary

我正在尝试对字节数组进行位填充,我需要填充的位数是 48(即 6 个字节)。下面是二进制字符串:

String paddingBinaryString = "100000000000000000000000000000000000000000000000"

但是,此二进制字符串的字节数组显示长度为 7(而不是 6!)。我将48位二进制字符串转字节数组的方式是:

byte[] paddingByteArr = new BigInteger(paddingBinaryString, 2).toByteArray();
System.out.println("paddingByteArr.length: " + paddingByteArr.length); //shows 7

一定有明显的错误,因为48位一定是6个字节,而不是7个,对吧?

toByteArraydocumentation

The array will contain the minimum number of bytes required to represent this BigInteger, including at least one sign bit

数字是正数,因此至少要在开头添加一个额外的零,需要一个完整的额外字节。表示是big endian,所以结果数组是

00000000 10000000 00000000 00000000 00000000 00000000 00000000 
       ^
       |
       *--- sign bit