public byte[] encodeToByteArray(List<Integer> input)
    {
        checkEncodeInputValidity(input);

        // Find address byte length by rounding up (totalBitLength / 8)
        byte[] address = new byte[(totalBitLength + 7) >> 3];

        if (!positiveIntegersOnly) {
            // Modify sign bits to preserve ordering between positive and negative integers
            int bitIndex = totalBitLength - 1;
            for (int value : input) {
                byte signBit = (value < 0) ? (byte) 0 : 1;
                address[bitIndex >> 3] |= signBit << (bitIndex & 7);
                bitIndex--;
            }
        }

        int bitIndex = positiveIntegersOnly ? totalBitLength - 1 : totalBitLength - encodingBits.size() - 1;
        // Interweave input bits into address from the most significant bit to preserve data locality
        for (int bitsProcessed = 0; bitsProcessed < maxBitLength; bitsProcessed++) {
            for (int index = 0; index < input.size(); index++) {
                if (bitsProcessed >= encodingBits.get(index)) {
                    continue;
                }
                int bitPosition = encodingBits.get(index) - bitsProcessed - 1;
                byte maskedBit = (byte) ((input.get(index) >> bitPosition) & 1);
                address[bitIndex >> 3] |= maskedBit << (bitIndex & 7);
                bitIndex--;
            }
        }

        return address;
    }
@Test
    public void testZOrderDifferentListSizes()
    {
        List<Integer> bitPositions = ImmutableList.of(8, 8, 8, 8, 8, 8, 8, 8);
        ZOrder zOrder = new ZOrder(bitPositions, true);
        List<Integer> intColumns = ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        try {
            zOrder.encodeToByteArray(intColumns);
            fail("Expected test to fail: input list size is greater than bit position list size.");
        }
        catch (IllegalArgumentException e) {
            String expectedMessage = format(
                    "Input list size (%d) does not match encoding bits list size (%d).",
                    intColumns.size(),
                    bitPositions.size());
            assertEquals(e.getMessage(), expectedMessage, format("Expected exception message '%s' to match '%s'", e.getMessage(), expectedMessage));
        }
    }