diff --git a/src/decode.c b/src/decode.c
index 5be506caf372f1b22f4bf73fb62b29ba35569649..309a8352c0dc3a0002777b60cf5fb9f42ae7192b 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -739,11 +739,11 @@ int aec_decode_init(struct aec_stream *strm)
     }
 
     if (strm->flags & AEC_DATA_SIGNED) {
-        state->xmax = UINT32_MAX >> (32 - strm->bits_per_sample + 1);
+        state->xmax = (INT64_C(1) << (strm->bits_per_sample - 1)) - 1;
         state->xmin = ~state->xmax;
     } else {
         state->xmin = 0;
-        state->xmax = UINT32_MAX >> (32 - strm->bits_per_sample);
+        state->xmax = (UINT64_C(1) << strm->bits_per_sample) - 1;
     }
 
     state->in_blklen = (strm->block_size * strm->bits_per_sample
diff --git a/src/encode.c b/src/encode.c
index db5c009086d52e5c8afb06f210266be6bbf71bbd..63dc6f4753fbb8e43d104d8c0c91612394fea206 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -849,12 +849,12 @@ int aec_encode_init(struct aec_stream *strm)
     state->rsi_len = strm->rsi * strm->block_size * state->bytes_per_sample;
 
     if (strm->flags & AEC_DATA_SIGNED) {
-        state->xmax = UINT32_MAX >> (32 - strm->bits_per_sample + 1);
+        state->xmax = (INT64_C(1) << (strm->bits_per_sample - 1)) - 1;
         state->xmin = ~state->xmax;
         state->preprocess = preprocess_signed;
     } else {
+        state->xmax = (UINT64_C(1) << strm->bits_per_sample) - 1;
         state->xmin = 0;
-        state->xmax = UINT32_MAX >> (32 - strm->bits_per_sample);
         state->preprocess = preprocess_unsigned;
     }