diff --git a/odxtools/standardlengthtype.py b/odxtools/standardlengthtype.py index 3793b69d..d427eb23 100644 --- a/odxtools/standardlengthtype.py +++ b/odxtools/standardlengthtype.py @@ -88,7 +88,10 @@ def __get_raw_mask(self, internal_value: AtomicOdxType) -> Optional[bytes]: else: sz = (odxrequire(self.get_static_bit_length()) + 7) // 8 - return self.bit_mask.to_bytes(sz, endianness) + max_value = (1 << (sz * 8)) - 1 + bit_mask = self.bit_mask & max_value + + return bit_mask.to_bytes(sz, endianness) def __apply_mask(self, internal_value: AtomicOdxType) -> AtomicOdxType: if self.bit_mask is None: