Repository: pymodbus-dev/pymodbus (Python)

Issue:
Discrete Input Order
I read the updated docs on 3.10 about bit ordering and I'm uncertain of the results. The docs read:

```
Example: Hex bytes: 0x00 0x01 
Older versions would deliver False * 8 True False * 7 
V3.10 deliver True False * 15
```

However, in my testing I see the following:

Discrete input address 1 and 7 are actually True

```
3.9.2
Discrete inputs: [False, True, False, False, False, False, False, True, False, False, False, False, False, False, False, False]
Set bits: [1, 7]
```

```
3.10.0
Discrete inputs: [False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, True]
Set bits: [9, 15]
```

Unless perhaps Hex bytes: 0x00 0x01 does not represent the active discrete inputs I think it does? Maybe there could be an example including sample active discrete inputs and the resulting true false list? 


Discussion:
It could be a bug. I believe the main focus was on coils.
Are you using FromRegisters() ? without knowing where you see the bit pattern it is a bit hard to help.
The code I used to get these results was just test code exactly as below:

```
result = client.read_discrete_inputs(address=50, count=10, device_id=1)
print(f"Discrete inputs: {result.bits}")
print("Set bits:", [i for i, b in enumerate(result.bits) if b])
```
The true bit pattern I am basing this on is from modbus poll.

<img width="496" height="648" alt="Image" src="https://github.com/user-attachments/assets/2eb9c7be-aab4-4c49-8ad4-0e714e427f80" />

<img width="700" height="1048" alt="Image" src="https://github.com/user-attachments/assets/1fa87314-a93c-4586-8ebf-17230bead345" />

If the 3.9.2 behavior is the intended result going forward into 3.10.x and 4.x, that's no problem. I can stay on 3.9.2 for now and wait for a new release. I started making some edits for the new behavior but wanted to make sure what was intended.
please add the pymodbus debug log se we can see the frame pymodbus receives.
3.10.0
```
2025-08-05 01:52:16,666 DEBUG base:72 Processing: 0x0 0x1 0x0 0x0 0x0 0x5 0x1 0x2 0x2 0x82 0x0
2025-08-05 01:52:16,666 DEBUG decoders:113 decoded PDU function_code(2 sub -1) -> ReadDiscreteInputsResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, True], registers=[], status=1retries=0)
```



3.9.2
```
2025-08-05 01:53:50,915 DEBUG base:91 Processing: 0x0 0x1 0x0 0x0 0x0 0x5 0x1 0x2 0x2 0x82 0x0
2025-08-05 01:53:50,917 DEBUG decoders:113 decoded PDU function_code(2 sub -1) -> ReadDiscreteInputsResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[False, True, False, False, False, False, False, True, False, False, False, False, False, False, False, False], registers=[], status=1)
```
Thanks, it looks as if the bytes are rotated, which is not correct.

I will check the test harness later because I thought this was tested.
Hey no worries, thanks for looking into it so quickly.

So just to be clear, this means 3.9.2 is the intended behavior and 3.11.0 will revert back to this behavior? So jumping from 3.9.2 to 3.11.0 should have no order change and this is the expected behavior going forward?
for bytes yes, but word are not corrected for little endian in 3.9.2
I'm so sorry, I am somewhat naive on the very low level pymodbus implementations here, so I still have some confusion.

From how I understand it, the client and read_discrete_inputs does not have a big vs little endian input to alter how the results come back. So when you say "word are not corrected for little endian", does this mean specifically in relation to the convert_from_registers and convert_to_registers type of functions?

If that's the case then does that mean that the results of read_discrete_inputs will be always the same from 3.9.2 to 3.11.0 and going forward? Or will read_discrete_inputs be different in some conditions now?
If your CPU is little endian then the pack/unpack routines converts from big endian to little endian.

The convert_from/convert_to functions use the pack/unpack methods just as all pdu classes does.

v3.11.0 should work correctly....and going forward to v4.0.0 there will surely be changes because response.bits will be replaced by a more generic response.values, and you can e.g. call read_discrete_inputs and ask to have int32 (or have [bool] which will be the default).
@janiversen Is it possible for you to review this one more time. I apologize, I was doing more investigation just to ensure I was understanding correctly and the results are not what I expected. 

I am running this test on a little endian CPU. Collected via `lscpu | grep -i endian`.

```
Byte Order:                      Little Endian
```

I setup this test to attempt better understanding where the effective difference is between 3.9.2 and 3.11.0.

```python
from pymodbus import __version__ as pymodbus_version
from pymodbus.client import ModbusTcpClient
from pymodbus import pymodbus_apply_logging_config
pymodbus_apply_logging_config("DEBUG")

def test_discrete_inputs():
    print(f"PyModbus version: {pymodbus_version}")
    print('-'*100)
    
    client = ModbusTcpClient(host="127.0.0.1", port=509)
    
    client.connect()


    if tuple(map(int, pymodbus_version.split('.'))) <= (3, 9, 2):
        result = client.read_discrete_inputs(address=0, count=8, slave=1)
    else:
        result = client.read_discrete_inputs(address=0, count=8, device_id=1)
        
    print('-'*100)
    print(f"Discrete inputs: {result.bits}")
    print(f"Set bits: {[i for i, b in enumerate(result.bits) if b]}")
    print('-'*100)
    big_endian_bits = client.convert_from_registers(result.bits, word_order='big', data_type=client.DATATYPE.BITS)
    print(f"Big endian: {big_endian_bits}")        
    print(f"Set bits: {[i for i, b in enumerate(big_endian_bits) if b]}")
    print('-'*100)
    little_endian_bits = client.convert_from_registers(result.bits, word_order='little', data_type=client.DATATYPE.BITS)
    print(f"Little endian: {little_endian_bits}")        
    print(f"Set bits: {[i for i, b in enumerate(little_endian_bits) if b]}")
    
    client.close()

if __name__ == "__main__":
    test_discrete_inputs()
```

After running it on both versions I got these results:

```
PyModbus version: 3.9.2
----------------------------------------------------------------------------------------------------
2025-08-05 14:43:24,505 DEBUG tcp:195 Connection to Modbus server established. Socket ('127.0.0.1', 50806)
2025-08-05 14:43:24,507 DEBUG base:91 Processing: 0x0 0x1 0x0 0x0 0x0 0x4 0x1 0x2 0x1 0x41
2025-08-05 14:43:24,508 DEBUG decoders:113 decoded PDU function_code(2 sub -1) -> ReadDiscreteInputsResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[True, False, False, False, False, False, True, False], registers=[], status=1) 
2025-08-05 14:43:24,508 DEBUG base:101 Frame advanced, resetting header!!
----------------------------------------------------------------------------------------------------
Discrete inputs: [True, False, False, False, False, False, True, False]
Set bits: [0, 6]
----------------------------------------------------------------------------------------------------
Big endian: [False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
Set bits: [8, 104]
----------------------------------------------------------------------------------------------------
Little endian: [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False]
Set bits: [24, 120]
```

```
PyModbus version: 3.11.0
----------------------------------------------------------------------------------------------------
2025-08-05 14:42:52,095 DEBUG tcp:195 Connection to Modbus server established. Socket ('127.0.0.1', 51222)
2025-08-05 14:42:52,096 DEBUG base:72 Processing: 0x0 0x1 0x0 0x0 0x0 0x4 0x1 0x2 0x1 0x41
2025-08-05 14:42:52,097 DEBUG decoders:113 decoded PDU function_code(2 sub -1) -> ReadDiscreteInputsResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[True, False, False, False, False, False, True, False], registers=[], status=1retries=0) 
----------------------------------------------------------------------------------------------------
Discrete inputs: [True, False, False, False, False, False, True, False]
Set bits: [0, 6]
----------------------------------------------------------------------------------------------------
Big endian: [False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
Set bits: [8, 104]
----------------------------------------------------------------------------------------------------
Little endian: [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False]
Set bits: [24, 120]
```

In this case on a little endian cpu the results are identical. So in your docs when you indicated that the ordering will be different I still don't know if I understand in what circumstance they are expected to be different or I should say fixed. 

From your response I expected: `print(f"Discrete inputs: {result.bits}")` to be the same order for 3.9.2 and 3.11.0. But then convert_from_registers would be different. However, that doesn't seem to be the case and I'm not sure I understand.

Sorry for taking up your time but I appreciate your assistance!
I am not sure I really can help you further, If the result is what you want then why bother (unless you want to understand the code).

I explained the convert_to/from uses the same routines as the pdu classes, so I am really puzzled as to why you expect them to give you different results, that does not make a lot of sense.

If you want to understand it better, then I suggest you dive into the code.

convert_to/from uses the same as pdu, so I was expecting if that shared routine had a change going from 3.9.2 to 3.11.0 that we would see a change in the data when testing on 3.9.2 vs 3.11.0.

This may have been a bad assumption, I was only trying to understand what changed. Generally, the docs suggest beyond 3.9.2 there is an ordering change of the bits. You followed this with specifying on little endian cpu. In my testing I couldn't identify a reordering change from 3.9.2 to 3.11.0 from only the functions I tried. 

So I suppose the reordering must be somewhere else, I just wasn't aware of where. And I was attempting to understand it better just to make sure I have my repos interpreting the responses correctly based on the new possible reordering. Is there any function that would highlight a resulting difference going from 3.9.2 to 3.11.0? 
Not in the API, look at the code as suggested earlier.
Interesting. The title of "API changes 3.11.0" states there is a bit ordering change. And yet you state there is no difference that is testable via the API. Based on this, maybe there really is no API change from 3.9.2 to 3.11.0. Maybe it should be in another section and not the API change section if no change was made? This has been my only source of confusion.

Thought it might be okay to ask how to replicate the API changes noted in the "API changes 3.11.0". But I suppose if I get extra time I will read through the relevant source code and hope I don't encounter an API change, if one was made, on accident in production code. Since I don't have a way to identify it preemptively without reading the source code.

https://pymodbus.readthedocs.io/en/latest/source/api_changes.html
The API change in 3.11 is compared to 3.10 not 3.9 which you asked about.
3.9 to 3.10 have documented API / bit order changes.

3.10 to 3.11 have documented API / bit order changes.

But there are no document covering changes explicitly from 3.9 to 3.11, which was your question, so no there are no API function to show the difference between 3.9 and 3.11...the only thing you can do is use a function in 3.9 and in 3.11 and deduct the differences manually.

Understood, I appreciate the help.

3.10 made an API change. And 3.11 reverted this API change back to 3.9.2. 

Had a hard time understanding that from the docs but very possible that's on me. Thanks for the guidance and as always thanks for the development of pymodbus.
maybe it is because it did not "just" revert back to 3.9.2, it reverted the wrong byte ordering, nothing else.
When you say 'did not "just" revert', this hints that 3.11 did not entirely go back to 3.9.2. This suggests from 3.9.2 to 3.11 there is at least an API change. I am only asking what it is. What is the API change? 

As I understand it, there is bit order, byte order, and word order. In my testing shown above, 3.9.2 and 3.11 have the same order for all 3.  So then what is the API change made from 3.9.2 to 3.11? I am not suggesting I think these are the only ways the API can change, but since I don't know what other ordering type, or other type of change in general, to check I wanted to clarify with you.

If the answer is that there is an API change but you are unable to provide me with what it is, that is also okay, maybe I should move this to the discussion section in case another user has discovered what the API change is?
The API change is documented for both versions and I have already told you a couple of times, that if you want to know the details you need to look at the code.

If 3.10 had been reverted don't you think that would have been mentioned in the change log and api change text.

I am pretty sure you will not get better answers in the discussions session.
Right, so it is not reverted. But I cannot reproduce a change at all from 3.9.2 to 3.11, as shown above. And hence my reason for reaching out. And you cannot provide guidance on why, without me reviewing the source code.

I understand, I will move to the discussions and see if anyone else can reproduce a change.

Thanks for the assistance.
Opened the discussion here: https://github.com/pymodbus-dev/pymodbus/discussions/2713

Key point to discuss for anyone interested is these results:

```
PyModbus version: 3.9.2
----------------------------------------------------------------------------------------------------
2025-08-06 12:39:05,914 DEBUG tcp:195 Connection to Modbus server established. Socket ('127.0.0.1', 37662)
2025-08-06 12:39:05,919 DEBUG base:91 Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x2 0x4 0x41 0x0 0x0 0x40
2025-08-06 12:39:05,919 DEBUG decoders:113 decoded PDU function_code(2 sub -1) -> ReadDiscreteInputsResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[True, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False], registers=[], status=1) 
```

```
PyModbus version: 3.11.0
----------------------------------------------------------------------------------------------------
2025-08-06 12:38:54,733 DEBUG tcp:195 Connection to Modbus server established. Socket ('127.0.0.1', 33540)
2025-08-06 12:38:54,744 DEBUG base:72 Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x2 0x4 0x41 0x0 0x0 0x40
2025-08-06 12:38:54,745 DEBUG decoders:113 decoded PDU function_code(2 sub -1) -> ReadDiscreteInputsResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[True, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False], registers=[], status=1retries=0) 
```

More info is in the discussion, but from the results I can not reproduce any API change from 3.9.2 to 3.11.0 even though there are known changes.



Patch:
diff --git a/API_changes.rst b/API_changes.rst
index 2de3f2625..4d40d4f88 100644
--- a/API_changes.rst
+++ b/API_changes.rst
@@ -2,8 +2,22 @@ API changes
 ===========
 Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes!
 
+API changes 3.11.0
+------------------
+- Revert wrong byte handling in v3.10.0
+  bit handling order is LSB-> MSB for each byte
+  REMARK: word are ordered depending on big/little endian
+  readCoils and other bit functions now return bit in logical order (NOT byte order)
+
+  Example:
+  Hex bytes: 0x00 0x01
+  delivers False * 8 True False * 7
+
+  Hex bytes: 0x01 0x03
+  delivers True False * 7 True True False * 6
+
 API changes 3.10.0
------------------
+------------------
 - ModbusSlaveContext replaced by ModbusDeviceContext
 - payload removed (replaced by "convert_to/from_registers")
 - slave=, slaves= replaced by device_id=, device_ids=
diff --git a/doc/source/upgrade_40.rst b/doc/source/upgrade_40.rst
index 3f3a764bb..8f12dc84a 100644
--- a/doc/source/upgrade_40.rst
+++ b/doc/source/upgrade_40.rst
@@ -4,7 +4,6 @@ Pymodbus 4.0 upgrade procedure
 Pymodbus 4.0 contains a number of incompatibilities with Pymodbus 3.x, however
 most of these are simple edits.
 
-
 Python 3.9
 ----------
 Python 3.9 is reaching end of life and from october 2025 no longer receives security updates.
diff --git a/pymodbus/pdu/pdu.py b/pymodbus/pdu/pdu.py
index 6b88ad5ff..30ea95a61 100644
--- a/pymodbus/pdu/pdu.py
+++ b/pymodbus/pdu/pdu.py
@@ -166,14 +166,15 @@ def pack_bitstring(bits: list[bool], align_byte=True) -> bytes:
     bits_extra = 8 if align_byte else 16
     if (extra := len(bits) % bits_extra):
         t_bits += [False] * (bits_extra - extra)
-    for bit in reversed(t_bits):
-        packed <<= 1
-        if bit:
-            packed += 1
-        i += 1
-        if i == 8:
-            ret += struct.pack(">B", packed)
-            i = packed = 0
+    for byte_inx in range(0, len(t_bits), 8):
+        for bit in reversed(t_bits[byte_inx:byte_inx+8]):
+            packed <<= 1
+            if bit:
+                packed += 1
+            i += 1
+            if i == 8:
+                ret += struct.pack(">B", packed)
+                i = packed = 0
     return ret
 
 
@@ -185,13 +186,11 @@ def unpack_bitstring(data: bytes) -> list[bool]:
         bytes 0x05 0x81
         result = unpack_bitstring(bytes)
 
-        [True, False, False, False] +
-        [False, False, False, True] +
-        [True, False, True, False] +
-        [False, False, False, False]
+        [True, False, True, False] + [False, False, False, False]
+        [True, False, False, False] + [False, False, False, True]
     """
     res = []
-    for byte_index in range(len(data) -1, -1, -1):
+    for _, t_byte in enumerate(data):
         for bit in (1, 2, 4, 8, 16, 32, 64, 128):
-            res.append(bool(data[byte_index] & bit))
+            res.append(bool(t_byte & bit))
     return res


Test patch:
diff --git a/test/client/test_client.py b/test/client/test_client.py
index bad622a7a..7f83e3183 100755
--- a/test/client/test_client.py
+++ b/test/client/test_client.py
@@ -170,55 +170,55 @@ def fake_execute(_self, _no_response_expected, request):
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [True],
-                [1],  # 0x00 0x01
+                [256],  # 0x01 0x00
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [True] + [False] * 15,
-                [1],  # 0x00 0x01
+                [256],  # 0x01 0x00
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [False] * 8 + [True] + [False] * 7,
-                [256],  # 0x01 0x00
+                [1],  # 0x00 0x01
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [False] * 15 + [True],
-                [32768],  # 0x80 0x00
+                [128],  # 0x00 0x80
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [True] + [False] * 14 + [True],
-                [32769],  # 0x80 0x01
+                [384],  # 0x01 0x80
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [False] * 8 + [True, False, True] + [False] * 5,
-                [1280],  # 0x05 0x00
+                [5],  # 0x00 0x05
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [True] + [False] * 7 + [True, False, True] + [False] * 5,
-                [1281],  # 0x05 0x01
+                [261],  # 0x01 0x05
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [True] + [False] * 6 + [True, True, False, True] + [False] * 5,
-                [1409], # 0x05 0x81
+                [33029], # 0x81 0x05
                 None,
             ),
             (
                 ModbusClientMixin.DATATYPE.BITS,
                 [False] * 8 + [True] + [False] * 7 + [True] + [False] * 6 + [True, True, False, True] + [False] * 5,
-                [1409, 256],  # 92340480 = 0x05 0x81 0x01 0x00
+                [1, 33029],  # 92340480 = 0x00 0x01 0x81 0x05
                 None,
             ),
         ],
diff --git a/test/pdu/test_pdu.py b/test/pdu/test_pdu.py
index 194cf1bd5..e4108528e 100644
--- a/test/pdu/test_pdu.py
+++ b/test/pdu/test_pdu.py
@@ -255,21 +255,21 @@ async def test_pdu_default_datastore(self, mock_context):
     @pytest.mark.parametrize(
         ("bytestream", "bitlist"),
         [
-            (b"\x00\x01", [True] + [False] * 15),
-            (b"\x01\x00", [False] * 8 + [True] + [False] * 7),
-            (b"\x80\x00", [False] * 15 + [True]),
-            (b"\x80\x01", [True] + [False] * 14 + [True]),
-            (b"\x05\x00", [False] * 8 + [True, False, True] + [False] * 5),
-            (b"\x05\x01", [True] + [False] * 7 + [True, False, True] + [False] * 5),
-            (b"\x05\x81", [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
-            (b"\x05\x81\x01\x00", [False] * 8 + [True] + [False] * 7 + [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
+            (b"\x01\x00", [True] + [False] * 15),
+            (b"\x00\x80", [False] * 15 + [True]),
+            (b"\x00\x01", [False] * 8 + [True] + [False] * 7),
+            (b"\x01\x80", [True] + [False] * 14 + [True]),
+            (b"\x00\x05", [False] * 8 + [True, False, True] + [False] * 5),
+            (b"\x01\x05", [True] + [False] * 7 + [True, False, True] + [False] * 5),
+            (b"\x81\x05", [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
+            (b"\x00\x01\x81\x05", [False] * 8 + [True] + [False] * 7 + [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
 
-            (b"\x00\x01", [True]),
-            (b"\x01\x00", [False] * 8 + [True]),
-            (b"\x05\x00", [False] * 8 + [True, False, True]),
-            (b"\x05\x01", [True] + [False] * 7 + [True, False, True]),
-            (b"\x05\x81", [True] + [False] * 6 + [True, True, False, True]),
-            (b"\x05\x81\x01\x00", [False] * 8 + [True] + [False] * 7 + [True] + [False] * 6 + [True, True, False, True]),
+            (b"\x01\x00", [True]),
+            (b"\x00\x01", [False] * 8 + [True]),
+            (b"\x00\x05", [False] * 8 + [True, False, True]),
+            (b"\x01\x05", [True] + [False] * 7 + [True, False, True]),
+            (b"\x81\x05", [True] + [False] * 6 + [True, True, False, True]),
+            (b"\x00\x01\x81\x05", [False] * 8 + [True] + [False] * 7 + [True] + [False] * 6 + [True, True, False, True]),
         ],
     )
     def test_bit_packing(self, bytestream, bitlist):
@@ -280,9 +280,9 @@ def test_bit_packing(self, bytestream, bitlist):
         ("bytestream", "bitlist"),
         [
             (b"\x01", [True]),
-            (b"\x01\x00", [False] * 8 + [True]),
+            (b"\x00\x01", [False] * 8 + [True]),
             (b"\x05", [True, False, True]),
-            (b"\x05\x01", [True] + [False] * 7 + [True, False, True]),
+            (b"\x01\x05", [True] + [False] * 7 + [True, False, True]),
         ],
     )
     def test_bit_packing8(self, bytestream, bitlist):
@@ -293,14 +293,17 @@ def test_bit_packing8(self, bytestream, bitlist):
         ("bytestream", "bitlist"),
         [
             (b"\x01", [True] + [False] * 7),
-            (b"\x00\x01", [True] + [False] * 15),
-            (b"\x01\x00", [False] * 8 + [True] + [False] * 7),
-            (b"\x80\x00", [False] * 15 + [True]),
-            (b"\x80\x01", [True] + [False] * 14 + [True]),
-            (b"\x05\x00", [False] * 8 + [True, False, True] + [False] * 5),
-            (b"\x05\x01", [True] + [False] * 7 + [True, False, True] + [False] * 5),
-            (b"\x05\x81", [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
-            (b"\x05\x81\x01\x00", [False] * 8 + [True] + [False] * 7 + [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
+            (b"\x01\x00", [True] + [False] * 15),
+            (b"\x00\x01", [False] * 8 + [True] + [False] * 7),
+            (b"\x00\x80", [False] * 15 + [True]),
+            (b"\x01\x80", [True] + [False] * 14 + [True]),
+            (b"\x00\x05", [False] * 8 + [True, False, True] + [False] * 5),
+            (b"\x01\x05", [True] + [False] * 7 + [True, False, True] + [False] * 5),
+            (b"\x81\x05", [True] + [False] * 6 + [True, True, False, True] + [False] * 5),
+            (b"\x05\x81\x01\x00", [True, False, True] + [False] * 5 +
+                                  [True] + [False] * 6 + [True] +
+                                  [True] + [False] * 7 +
+                                  [False] * 8),
         ],
     )
     def test_bit_unpacking(self, bytestream, bitlist):